0

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 ?

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
ghita
  • 2,746
  • 7
  • 30
  • 54
  • 1
    According to [the documentation](https://developer.android.com/reference/android/provider/AlarmClock?hl=en#ACTION_SET_TIMER), the action string for `ACTION_SET_TIMER` is `android.intent.action.SET_TIMER`, not `android.intent.action.MAIN`. – CommonsWare May 23 '22 at 14:59
  • I think in this case your tag might not need to be inside a one, but just directly inside . Try removing the uses-permission tag (unless you need some actual permissions) https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9 – Dissident Dev May 23 '22 at 15:27

1 Answers1

-1

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>
Martin Sch
  • 64
  • 2