Android:来自BroadcastReceiver的通知 [英] Android: notification from BroadcastReceiver

查看:76
本文介绍了Android:来自BroadcastReceiver的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个警报管理器,可以启动广播接收器. 这是我的广播接收器:

I have an alarm manager that starts a broadcast receiver. Here is my broadcast receiver:

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和支持库吗?

The broadcast starts in time, but there is no notification, only sound. Where is the text? What's wrong? Is it because I'm using API 10 and the support library?

推荐答案

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

Oh, I found the problem. The problem is in .setSmallIcon(0)...When I set some real resource, its ok, notification appear...

这篇关于Android:来自BroadcastReceiver的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆