我从后台服务发送一个通知。如果我点击该通知,它有时不会调用特定活动。 (很少次只是它的召唤)。
这是我的代码:
private void postNotification(String msg, int beaconID) {
if(!notifyMsg.equalsIgnoreCase(msg)){
notifyMsg = msg;
Log.e(TAG, "---------postNotification------- called");
notifyIntent = new Intent(this,
WelcomeHotel.class);
notifyIntent.putExtra("content", msg);
notifyIntent.putExtra("from_activity", ""+TAG);
notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(
BeaconMyService.this, 0, /*new Intent[] { notifyIntent }*/ notifyIntent,
/*PendingIntent.FLAG_UPDATE_CURRENT*/0);
Notification notification = new Notification.Builder(
BeaconMyService.this).setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Monitoring Region").setContentText(msg)
.setAutoCancel(true).setContentIntent(pendingIntent).build();
notification.setLatestEventInfo(getApplicationContext(), "Monitoring Region", ""+msg, pendingIntent);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notificationManager.notify(0, notification);
}
}
答案 0 :(得分:0)
setLastEventInfo()
此方法在API级别11中已弃用。请改用Notification.Builder。
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_LIGHTS;
应该
new Notification.Builder(BeaconMyService.this)
.setDefaults(Notification.DEFAULT_ALL)
...
如果使用minApi - pre-Honeycomb,则应更改一个字符串
//new Notification.Builder(BeaconMyService.this)
new NotificationCompat.Builder(BeaconMyService.this)