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级别可以做到这一点。