Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the package visibility in Android 11

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the package visibility in Android 11". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the package visibility in Android 11".

In order to better "accountable" the behavior of accessing installed applications, by default, applications targeting Android 11 (target API level is 30) will only detect partially filtered installed applications by default. If you want to get more information about the list of other installed applications, you need to add elements to the Android manifest within the application to broaden the scope of access.

In most common scenarios, including any intents started with startActivity (), you don't need to make any changes. Other scenarios, such as opening a specific third-party application directly from the interface of your application, require developers to explicitly declare the package name or intent filter signature of the application, as shown below:

...

Most common scenarios

Https://developer.android.google.cn/preview/privacy/package-visibility#use-cases-not-affected

Other scenes

Https://developer.android.google.cn/preview/privacy/package-visibility-use-cases

Intent filter signature

Https://developer.android.google.cn/preview/privacy/package-visibility#intent-signature

If you use Custom Tab to open the URL link, you may call resolveActivity () and queryIntentActivities () to launch a non-browser application (provided you have installed the application that handles the URL). In Android 11, there is a better way to deal with this: use intent's FLAG_ACTIVITY_REQUIRE_NON_BROWSER tags instead of querying other applications. If the browser is launched when you call startActivity () with this tag, an ActivityNotFoundException exception is thrown, and your application can handle the exception and use Custom Tab to open the URL link instead.

Try {val intent = Intent (ACTION_VIEW Uri.parse (url). Apply {/ / non-browser applications will directly process the URL (by default) / / users can also select non-browser applications addCategory (CATEGORY_BROWSABLE) flags = FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_REQUIRE_NON_BROWSER} startActivity (intent)} catch (e: ActivityNotFoundException) {/ / can only use browser applications in the disambiguation dialog box Or the browser is used by default to process the intent. }

Custom Tab

Https://developers.google.cn/web/android/custom-tabs

A better way.

Https://developer.android.google.cn/preview/privacy/package-visibility-use-cases#avoid-a-disambiguation-dialog

FLAG_ACTIVITY_REQUIRE_NON_BROWSER

Https://developer.android.google.cn/preview/privacy/package-visibility#web-intent-non-browser-app

In rare cases, your application may need to query or interact with all installed applications on the device, no matter what components they contain. To allow your application to see all other installed applications, Android 11 introduces QUERY_ALL_PACKAGES permissions. In the upcoming policy update, Google Play will provide guidance for applications that require QUERY_ALL_PACKAGES permissions. You can add elements to your application by setting API Level to 30 and using the corresponding Android Gradle plug-ins from Android Studio 3.2 and the latest release. You can find more usage information and use cases about package availability in the developer document, Android 11, package visibility.

QUERY_ALL_PACKAGES https://developer.android.google.cn/preview/privacy/package-visibility#all-apps

Developer documentation-package visibility https://developer.android.google.cn/preview/privacy/package-visibility in Android 11

Android Studio and Gradle support for this feature

If you are using the Android Gradle plug-in version 4.1 and above, you can use the new element normally, because the old version of the Gradle plug-in is not compatible with this element. If you use or rely on libraries or SDK that support Android 11, it may cause manifest conflicts and the error of merging manifest. For example, when building an application, you might see the following error in Build Output Window:

Android resource linking failed / Users/sample/AndroidStudioProjects/MyApp/app/build/intermediates/merged_manifests/debug/AndroidManifest.xml:18: error: unexpected element found in

There may also be an error message in Build Output Window that guides you to view the Manifest merge log (Manifest merger logs):

Manifest merger failed with multiple errors, see logs

When you expand the Merged Manifest view, an additional error message appears:

Error: Missing 'package' key attribute on element package

Merged Manifest view

Https://developer.android.google.cn/studio/build/manifest-merge#inspect_the_merged_manifest_and_find_conflicts

Fix problems with the Android Gradle plug-in

The best way to resolve the above errors is to upgrade the Android Gradle plug-in to version 4.1 Beta. However, not all developers can use the latest version, and some projects may rely on older versions of Gradle or code bases, which have compatibility issues with version 4.1 of the Android Gradle plug-in. Therefore, we recently released a small version (dot releases) upgrade for the Android Gradle plug-in to be compatible with elements:

Upgrade the Android Gradle plug-in to version 4.1 Beta https://developer.android.google.cn/studio/releases/gradle-plugin#updating-plugin

Upgrade https://developer.android.google.cn/studio/releases/gradle-plugin#4-0-0 for small version (dot releases)

For example, if you are using version 4.0.0 of the Android Gradle plug-in, you can upgrade the related dependencies to the corresponding version in the figure above in a project-level build.gradle file.

Buildscript {repositories {google () jcenter ()} dependencies {/ / classpath 'com.android.tools.build:gradle:4.0.0' classpath' com.android.tools.build:gradle:4.0.1'}} Thank you for reading. This is the content of "what is package visibility in Android 11". After studying this article I believe you have a deeper understanding of what the package visibility is in Android 11, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report