3D Touch功能是桌面讀取App所指定的資源,資源可以在App的resource里面,也可以在本地可讀路徑里面。
3D Touch的Menu最多只有4個,在動態(tài)接口和靜態(tài)接口同時存在的時候會優(yōu)先使用靜態(tài)接口,當靜態(tài)接口不存在或者是不夠4個時候,才會讀取動態(tài)接口。
靜態(tài)接口和動態(tài)接口都是一個JSON文件,可以在AndroidManifest.xml里面來配置路徑,如下邊代碼:
AndroidManifest
<application
android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
>
<activity
android:name="MyActivity"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data android:name="forceTouchStatic" android:value="test1"/>
<meta-data android:name="forceTouchDynamic" android:value="/data/data/com.example.testForceTouch/files/text.txt"/>
</activity>
<activity-alias
android:name="TestAndroidAlias"
android:targetActivity=".MyActivity"
android:label="testAndroidlias"
android:icon="@drawable/ani16">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="forceTouchStatic" android:value="test1"/>
</activity-alias>
</application>
靜態(tài)接口:
默認會在App的raw目錄下讀取xiaomi_static_config,也可以自定義raw目錄下文件的名稱
<meta-data android:name="forceTouchStatic"
android:value="test1"/>
動態(tài)接口:
動態(tài)接口需要提供接口文件的路徑,只能使用meta-data定義,建議在自己的私有目錄,建一個全局只讀的文件
<meta-data android:name="forceTouchDynamic"
android:value="/data/data/com.example.testForceTouch/files/text.txt"/>
1.接口文件:
參考附件,里面就是一個json,見附件。
xiaomi_static_config:http://f3.market.xiaomi.com/download/MiPass/02b9f94709c4e410912e10203744edc27eb824a3b/xiaomi_static_config.zip
備注:
title是主標題,desc是副標題,
type有三個選項,用來表示intent要調起的是什么,activity,broadcast,service
intent就是intent.toUri(0)返回的字符串。
image就是icon
其中title,desc和image是資源name,桌面會到各個app下去找該name對應的字符串和圖片。
title_raw和desc_raw是直接使用里面的文字,不會去取資源。
image_path指定一張圖片路徑,桌面會去該路徑加載圖片。
注:靜態(tài)接口里面的json也可以使用title_raw,desc_raw和image_path。同理動態(tài)接口的json文件也可以使用title,desc,image。