Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android,访问所有通知_Android_Notifications - Fatal编程技术网

Android,访问所有通知

Android,访问所有通知,android,notifications,Android,Notifications,在安卓系统中,如果用户将特定应用程序的“显示通知”设置为关闭,通知是否仍会创建?如果是的话,是否有可能访问这些已创建但未显示的通知?< P>作为一个例子,考虑到创建状态栏通知,下面使用代码: NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon) .setContent

在安卓系统中,如果用户将特定应用程序的“显示通知”设置为关闭,通知是否仍会创建?如果是的话,是否有可能访问这些已创建但未显示的通知?

< P>作为一个例子,考虑到创建状态栏通知,下面使用代码:

NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle("My notification")
        .setContentText("Hello World!");
NotificationManager mNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);    
mNotificationManager.notify(mId, mBuilder.build());
要发布此通知,请使用以下代码:

NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.notification_icon)
        .setContentTitle("My notification")
        .setContentText("Hello World!");
NotificationManager mNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);    
mNotificationManager.notify(mId, mBuilder.build());
但由于“显示通知”已关闭,上述代码不会在状态栏上显示通知。
如您所见,尽管
NotificationCompat.Builder
创建了一个通知对象/实例,并用其他详细信息(如标题或文本等)填充了该对象/实例,但由于用户的首选项设置,系统不允许发布,因此您无法访问该对象/实例

此外,自Android 4.1以来,用户可以从应用程序管理器关闭应用程序通知,但没有API可以从应用程序代码(即在非根设备上)实现相同的功能。而且不可能禁用来自其他应用程序的通知,您只能控制由您自己的应用程序生成的通知

您必须记住的几点提示:
1.作为开发商,我们无法知道通知电话是否有效。因此,如果我真的需要检查当前应用程序的通知是否已禁用,则API中没有此类设置。
2.你真的不该管它。假设你的通知成功了。如果用户明确禁用了您的通知,那么他/她可能有很好的理由这样做,并且您的应用程序不应该关心通知是否显示