Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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 - Fatal编程技术网

Android:来自广播接收器的通知

Android:来自广播接收器的通知,android,Android,我有一个启动广播接收器的警报管理器。 这是我的广播接收器: public class AlarmBrodcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent arg1) { showNotification(context); } private void showNotification(Context

我有一个启动广播接收器的警报管理器。 这是我的广播接收器:

public class AlarmBrodcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent arg1) {
        showNotification(context);
    }

    private void showNotification(Context context) {
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
                new Intent(context, MyActivity.class), 0);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                .setSmallIcon(0)
                .setContentTitle("My notification")
                .setContentText("Hello World!");
        mBuilder.setContentIntent(contentIntent);
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
        mBuilder.setAutoCancel(true);
        NotificationManager mNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.notify(1, mBuilder.build());

    }  
}

广播及时开始,但没有通知,只有声音。文本在哪里?发生了什么?是因为我使用的是API 10和支持库吗?

哦,我发现了问题。问题出在.setSmallIcon(0)…当我设置一些实际资源时,没有问题,会出现通知…

我没有遇到您的具体问题,但由于您的帮助,我设法确保在我的API级别可以做到这一点。