Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Lollipop App Notification Settings

In Android Lollipop, when you long press a Notification, it gives you access to settings for that Notification's app, such as priority, or simply blocking it. Is there an intent that I can use to access those settings?

like image 472
Kyle Jahnke Avatar asked Mar 16 '23 21:03

Kyle Jahnke


2 Answers

Found the answer here - https://plus.google.com/+CyrilMottier/posts/YY6tbJrJMra

You need to add this to the activity you want to be attached to that settings icon

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.NOTIFICATION_PREFERENCES" />
</intent-filter>

like image 147
Shmuel Avatar answered Mar 29 '23 15:03

Shmuel


In addition to the correct answer from @shmuel :

In case you want this "App settings" system button to jump to one specific fragment of your app's Settings activity deriving from PreferenceActivity, you can create a dummy intermediary activity to handle the intent-filter as details above, and then in this activity you simply do:

public class DeepSettingsFragmentDummyActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent settingsIntent = new Intent(this, SettingsActivity.class);
        // Standard mechanism for a PreferenceActivity intent to indicate
        // which fragment to activate automatically.
        settingsIntent.putExtra( PreferenceActivity.EXTRA_SHOW_FRAGMENT,
            YourTargetPreferenceFragment.class.getName());

        startActivity(settingsIntent);
        finish();
    }
}

This code automatically launches the YourTargetPreferenceFragment fragment, and then dismisses itself (finish()) so as to not remain in the activity stack when the user hits Back.

Your Manifest must contain:

    <activity
        android:name=".DeepSettingsFragmentDummyActivity"
        android:label="...">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.NOTIFICATION_PREFERENCES" />
        </intent-filter>
    </activity>
like image 21
Gabriel Avatar answered Mar 29 '23 17:03

Gabriel