我有一个启动广播接收器的警报管理器。这是我的广播接收器:
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 和支持库吗?