【问题标题】:Android Lollipop App Notification SettingsAndroid Lollipop 应用通知设置
【发布时间】:2015-05-01 16:20:53
【问题描述】:

在 Android Lollipop 中,当您长按通知时,您可以访问该通知的应用程序的设置,例如优先级,或者只是阻止它。是否有我可以用来访问这些设置的意图?

【问题讨论】:

标签: android notifications android-notifications android-5.0-lollipop android-settings


【解决方案1】:

除了@shmuel 的正确答案:

如果您希望此“应用程序设置”系统按钮跳转到派生自 PreferenceActivity 的应用程序设置活动的一个特定片段,您可以创建一个虚拟中间活动来处理上述意图过滤器,然后在此您只需要做的活动:

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();
    }
}

此代码自动启动 YourTargetPreferenceFragment 片段,然后自行关闭 (finish()),以免在用户点击返回时留在活动堆栈中。

您的清单必须包含:

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

【讨论】:

  • 您实际上可以按原样打开主要活动,并检查intent.getCategories().contains("android.intent.category.NOTIFICATION_PREFERENCES") 它将判断它是否是从此按钮打开的
【解决方案2】:

在这里找到答案 - https://plus.google.com/+CyrilMottier/posts/YY6tbJrJMra

您需要将此添加到要附加到该设置图标的活动中

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    相关资源
    最近更新 更多