إذا أردت معرفة ما إذا كان المتصفِّح التلقائي أو أي متصفِّح على الجهاز يتيح استخدام علامات التبويب المخصَّصة، استخدِم مساعد getPackageName
في CustomTabsClient
:
String packageName = CustomTabsClient.getPackageName(
context,
Collections.emptyList()
);
if (packageName == null) {
// Custom Tabs are not supported by the default browser
}
يمكنك أيضًا التحقّق مما إذا كان هناك أي متصفّح على الجهاز يتيح استخدام علامات التبويب المخصّصة باتّباع الخطوات التالية:
// Get all apps that can handle VIEW intents and Custom Tab service connections.
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
PackageManager packageManager = context.getPackageManager();
List<ResolveInfo> viewIntentHandlers = packageManager.queryIntentActivities(activityIntent, 0);
// Get a package that supports Custom Tabs
String packageName = CustomTabsClient.getPackageName(
context,
viewIntentHandlers,
true /* ignore default */
);
if (packageName == null) {
// Custom Tabs are not supported by any browser on the device
}
تم إدخال تغييرات على مستوى رؤية الحزمة في Android 11. إذا كان تطبيق Android يستهدف المستوى 30 لواجهة برمجة التطبيقات أو مستوى أعلى، يجب إضافة قسم طلبات البحث التالي إلى AndroidManifest.xml
، وإلا فلن يعرض مقتطف الرمز أعلاه النتائج:
<queries>
<intent>
<action android:name=
"android.support.customtabs.action.CustomTabsService" />
</intent>
</queries>