如何确定系统活动支持哪些意图数据。

3

我正在检查这段代码(它打开了特定应用的使用设置权限):

val intent = Intent("android.settings.USAGE_ACCESS_SETTINGS")
val uri: Uri = Uri.fromParts("package", "com.my.example", null)
intent.data = uri
context.startActivity(intent)

我理解 "USAGE_ACCESS_SETTINGS" 部分,它已有文档记录:https://developer.android.com/reference/android/provider/Settings#ACTION_USAGE_ACCESS_SETTINGS

但是这段代码的作者如何想出 "package" intent 数据的呢?每个 intent 数据是否有允许的列表可供查询?

我在文档中找不到相关信息。也许在 Android 源代码中有一些内容可以阅读?

1个回答

1
它为特定应用程序打开使用设置权限。并不一定如此。它没有在任何特定设备上工作的要求。AOSP版本的设置应用程序源代码中有两个活动响应该Intent操作。
        <activity
            android:name="Settings$UsageAccessSettingsActivity"
            android:exported="true"
            android:label="@string/usage_access_title">
            <intent-filter android:priority="1">
                <action android:name="android.settings.USAGE_ACCESS_SETTINGS" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
                android:value="com.android.settings.applications.manageapplications.ManageApplications" />
            <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                       android:value="true" />
        </activity>

        <activity
            android:name="Settings$AppUsageAccessSettingsActivity"
            android:exported="true"
            android:label="@string/usage_access_title">
            <intent-filter>
                <action android:name="android.settings.USAGE_ACCESS_SETTINGS"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:scheme="package"/>
            </intent-filter>
            <meta-data
                android:name="com.android.settings.FRAGMENT_CLASS"
                android:value="com.android.settings.applications.UsageAccessDetails"/>
        </activity>

(来自Android 12分支的代码)
第二个代码片段中有`<data android:scheme="package"/>`,与您的代码片段中的`Uri`相对应。
请注意,设备制造商经常更改设置应用程序,并且没有要求他们支持此特定活动。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接