Android 11 軟體包可見性 適配
目錄
- Android 11 軟體包可見性 適配
- 一、軟體包可見性說明
- 1. 不受影響的特定場景
- 2. 受影響的方法串列
- 二、軟體包可見性配置
- 1. 檢查是否有可用瀏覽器,例如需要打開外部瀏覽器
- 2. 檢查設備能否打開給定檔案,如需要打開 pdf、zip
- 3. 創建自定義共享表單,如分享圖片、檔案
- 4. 顯示自定義文字選擇操作,如選中一段文字,進行復制、粘貼操作
- 5. 連接到文字轉語音引擎
- 6. 連接到語音識別服務
- 7. 顯示聯系人的自定義資料行
- 8. 連接到媒體瀏覽器服務
- 9. 配置訪問 微信,支付寶,QQ,微博
- 10. 配置查詢所有應用及與之互動(以上均可不配置,但 gp 會嚴格審核)
- 附 Github 原始碼:
一、軟體包可見性說明
如果應用以 Android 11(API 級別 30)或更高版本為目標平臺,在默認情況下,系統會自動讓部分應用對您的應用可見,但會隱藏其他應用,
通過讓部分應用在默認情況下不可見,系統可以了解應向應用顯示哪些其他應用,這樣有助于鼓勵最小權限原則,
注意:
- 如果您的應用以 Android 10(API 級別 29)或更低版本為目標平臺,那么全部應用均會自動對您的應用可見,
- 即使您的應用以 Android 11(API 級別 30)或更高版本為目標平臺,特定場景不會受影響,
1. 不受影響的特定場景
- 實作 Android 核心功能的某些系統軟體包,如媒體提供程式,
- 使用 startActivityForResult() 方法啟動其他應用的某個頁面,
- 通過 Content Provider 訪問的應用,
- 具有 Content Provider 的任何應用,且應用已被授予 URI 權限來訪問該 Content Provider,
- 可以使用隱式或顯式 intent 來啟動另一應用的 activity,無論這個應用是否對您的應用可見,
2. 受影響的方法串列
// 檢索可以為給定意圖執行的所有 activity
PackageManager.queryIntentActivities(intent, flag)
// 檢索可以匹配給定意圖的所有服務
PackageManager.queryIntentServices(intent, flag)
// 檢索可以處理給定意圖廣播的所有接收器
PackageManager.queryBroadcastReceivers(intent, flag)
// 查詢內容提供者
PackageManager.queryContentProviders(processName, uid, flag)
// 獲取為當前用戶安裝的所有軟體包的串列,
PackageManager.getInstalledPackages(flag)
// 獲取已安裝的應用程式
PackageManager.getInstalledApplications(flag)
二、軟體包可見性配置
1. 檢查是否有可用瀏覽器,例如需要打開外部瀏覽器
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>
</manifest>
2. 檢查設備能否打開給定檔案,如需要打開 pdf、zip
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="*/*" />
</intent>
</queries>
</manifest>
3. 創建自定義共享表單,如分享圖片、檔案
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
</manifest>
4. 顯示自定義文字選擇操作,如選中一段文字,進行復制、粘貼操作
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT" />
<data android:mimeType="text/plain" />
</intent>
</queries>
</manifest>
5. 連接到文字轉語音引擎
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<intent>
<action android:name="android.intent.action.TTS_SERVICE" />
</intent>
</queries>
</manifest>
6. 連接到語音識別服務
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<intent>
<action android:name="android.speech.RecognitionService" />
</intent>
</queries>
</manifest>
7. 顯示聯系人的自定義資料行
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<!-- Allows the app to read the "contacts.xml" file from the other apps. -->
<intent>
<action android:name="android.accounts.AccountAuthenticator" />
</intent>
<!-- Allows the app to load an icon corresponding to the custom MIME type. -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data
android:host="com.android.contacts"
android:mimeType="vnd.android.cursor.item/*"
android:scheme="content" />
</intent>
</queries>
</manifest>
8. 連接到媒體瀏覽器服務
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<intent>
<action android:name="android.media.browse.MediaBrowserService" />
</intent>
</queries>
</manifest>
9. 配置訪問 微信,支付寶,QQ,微博
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<queries>
<!--微信-->
<package android:name="com.tencent.mm" />
<!--支付寶-->
<package android:name="com.eg.android.AlipayGphone" />
<package android:name="hk.alipay.wallet" />
<!--QQ-->
<package android:name="com.tencent.qqlite" />
<package android:name="com.tencent.mobileqq" />
<!--新浪微博-->
<package android:name="com.sina.weibo" />
</queries>
</manifest>
10. 配置查詢所有應用及與之互動(以上均可不配置,但 gp 會嚴格審核)
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
附 Github 原始碼:
AndroidManifest.xml
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/392165.html
標籤:其他
上一篇:Facedemo填空代碼
下一篇:ATX 移動設備共享平臺
