
參考來(lái)源:
https://blog.andreamagni.eu/2019/02/how-to-add-android-app-shortcuts-to-a-fmx-application
第一步:
修改工程根目錄下面的 AndroidManifest.template.xml,如果沒(méi)有這個(gè)文件,按一下 Ctrl + F9,編譯一次就有了。
找到一下字段,插入一節(jié):
......
</intent-filter>
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
</activity>
......
第二步:
新建立一個(gè) XML 文件,編碼格式為 UTF-8,將以下內(nèi)容復(fù)制進(jìn)去,然后命名為 shortcuts.xml
在 Deployment 中加進(jìn)去,remotepath 設(shè)置為 res\xml\
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="writedailyid"<!--這個(gè)是唯一的 id,不能重復(fù)-->
android:enabled="true"
android:icon="@drawable/writedaily_128"<!--這個(gè)是快捷菜單左邊顯示的圖標(biāo),大小為128x128-->
android:shortcutShortLabel="@string/writedaily"<!--這個(gè)是顯示的短標(biāo)題-->
android:shortcutLongLabel="@string/writedaily"<!--這個(gè)是顯示的長(zhǎng)標(biāo)題-->
android:shortcutDisabledMessage="@string/writedaily_disabled"><!--這個(gè)是禁用后菜單的標(biāo)題-->
<intent
android:action="android.intent.action.WRITEDAILY"<!--重要!這個(gè)是你的App獲取菜單點(diǎn)擊后的返回值->
android:targetPackage="com.sail2000studio.dailybook"<!--重要!這個(gè)是 APP 的名稱(chēng)-->
android:targetClass="com.embarcadero.firemonkey.FMXNativeActivity"/><!--這個(gè)不能動(dòng)-->
<categories android:name="android.shortcut.conversation"/><!--這個(gè)不能動(dòng)-->
</shortcut>
</shortcuts>
第三步:
新建立一個(gè) XML 文件,編碼格式為 UTF-8,將以下內(nèi)容復(fù)制進(jìn)去,然后命名為 strings.xml 保存到工程根目錄下
(注意:在 delphi 10.3.2 前例如 10.3.1,工程里面的 Deployment 是不含有 strings.xml 的,delphi 10.3.2開(kāi)始自動(dòng)有了,煩惱開(kāi)始來(lái)了...)。在 delphi 10.3.2不要在 Deployment 中加入,即使加入,也會(huì)被 delphi 用自己的干掉的,會(huì)導(dǎo)致找不到對(duì)應(yīng)的資源而編譯失敗。(如果是10.3.1 可以加,remote path設(shè)置為 res\values\ )
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--注意,這里的name="writedaily"與上面第二步的 shortcuts.xml 某些字段是一一對(duì)應(yīng)的 -->
<string name="writedaily">這里是菜單</string><!--菜單顯示的文字-->
<string name="writedaily_disabled">菜單已禁用</string> <!--禁用菜單后顯示的文字-->
</resources>
第四步:
制作一個(gè) 128x128 的圖片,作為菜單圖標(biāo),PNG 格式,命名為 shortcuts.xml 中的 <writedaily_128>相同,例如 writedaily_128.png,在 Deployment 中加入,remote path 設(shè)置為 res\drawable
第五步:
編寫(xiě)代碼響應(yīng)菜單
var
s: string;
s := JStringToString(TAndroidHelper.Activity.getIntent.getAction);
需要引用單元:
uses
Androidapi.JNI.App,
Androidapi.JNI.JavaTypes,
Androidapi.Helpers
第六步:
編譯工程,編譯完成后,去 Android\debug 或 Android\release 的目錄中, 用上面的 strings.xml 覆蓋掉 delphi 自己搞出來(lái)的 strings.xml(麻煩?。?。
第七步:
在 Deployment 的工具列,按一下 Deploy 發(fā)布 Apk,完成后,安裝 Apk 到手機(jī)上,測(cè)試一下看?