【问题标题】:Android Enable/Disable Notification access AutomaticallyAndroid 自动启用/禁用通知访问
【发布时间】:2015-11-13 12:34:55
【问题描述】:

您好,如何启用/禁用我的通知访问设置 自动应用?

【问题讨论】:

  • 在设置中的选项>安全允许您的应用访问通知!
  • 我正在阅读来自 whatsapp 的通知!

标签: android notifications settings


【解决方案1】:

可以使用以下代码完成:

ContentResolver cr = context.getContentResolver();
String setting = Settings.Secure.ENABLED_NOTIFICATION_LISTENERS;
String permissionString = Settings.Secure.getString(cr, setting);
if(permissionString == null || !permissionString.contains("com.abc.xyz"))
{
    ComponentName analytics = new ComponentName("com.abc.xyz", "com.abc.xyz.LMN");
    if(permissionString == null)
        permissionString = "";
    else
        permissionString += ":";
    permissionString += analytics.flattenToString();
    Settings.Secure.putString(cr, setting, permissionString);
}

请注意,应用程序必须是系统应用程序或使用框架 res apk 使用的相同密钥签名才能写入 Setting.Secure 数据库。

【讨论】:

  • 这个“com.abc.xyz”是什么意思?
  • 它是应用程序的包名,例如 com.whatsapp for WhatsApp
【解决方案2】:

我认为这是不可能的。你必须去设置,你必须打开。你可以给像这样的设置意图

startActivity(new Intent(Settings.ACTION_SECURITY_SETTINGS));

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多