Home > other >  how to tell what intent data is supported for a system activity
how to tell what intent data is supported for a system activity

Time:02-18

I am inspecting this piece of code (it opens Usage Settings permissions for a particular app):

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

I understand the "USAGE_ACCESS_SETTINGS" part, it is documented: https://developer.android.com/reference/android/provider/Settings#ACTION_USAGE_ACCESS_SETTINGS

But how did the author of this code come up with the "package" intent data? Is there any list of allowed intent data for each of intents?

I cannot find any info about this in the docs. Maybe there's something in the Android source code I can read?

CodePudding user response:

it opens Usage Settings permissions for a particular app

Not necessarily. There is no requirement that it works on any particular device.

Maybe there's something in the Android source code I can read?

The source code to the AOSP edition of the Settings app has two activities that respond to that Intent action:

        <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>

(code from an Android 12 branch)

The second one has <data android:scheme="package"/>, lining up with that Uri from your code snippet.

Just bear in mind that device manufacturers routinely change the Settings app, and there is no requirement for them to support this particular activity.

  • Related