What is the right declaration for AlarmClock package visibility?

61 Views Asked by At

I have a hard time finding the proper manifest query permission declaration when using AlarmClock intent, related with android 11 package visibility.

val intent =  Intent(AlarmClock.ACTION_SET_TIMER)    
intent.resolveActivity(requireContext().packageManager) // <= returns null

If I add into manifest:

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
    <queries>
        <intent>
            <action android:name="android.intent.action.MAIN" />
        </intent>
    </queries>

then I get the right component, but I know that QUERY_ALL_PACKAGES is not recommended so:

What is the right declaration for AlarmClock package visibility ?

1

There are 1 best solutions below

0
On

You should use permission like this source:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test">
    <uses-permission android:name="android.permission.SET_ALARM"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        </application>