我现在编码一个android应用程序约4个月,im当前正在系统通知上出现错误。 问题是,即时通讯从多个兴趣点添加邻近警报,当它接近特定点时,它会发送系统通知。但是现在,当我接近一个以上的点时,它会发送正确数量的通知,但它们都是相同的,具有相同的标题和文本,并且即时通过关于意图的不同信息。 我的代码是:Android通知错误
MainActivity:
private void addProximityAlert(double latitude, double longitude, String type, int id, String object) {
Intent intent = new Intent(PROX_ALERT_INTENT);
intent.putExtra("type", type);
intent.putExtra("id", id);
intent.putExtra("object", object);
PendingIntent proximityIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
locationManager.addProximityAlert(
latitude, // the latitude of the central point of the alert region
longitude, // the longitude of the central point of the alert region
POINT_RADIUS, // the radius of the central point of the alert region, in meters
PROX_ALERT_EXPIRATION, // time for this proximity alert, in milliseconds, or -1 to indicate no expiration
proximityIntent // will be used to generate an Intent to fire when entry to or exit from the alert region is detected
);
IntentFilter filter = new IntentFilter(PROX_ALERT_INTENT);
registerReceiver(new ProximityReceiver(), filter);
}
感应接收器:
public class ProximityReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String key = LocationManager.KEY_PROXIMITY_ENTERING;
Boolean entering = intent.getBooleanExtra(key, false);
int id = intent.getIntExtra("id", 0);
String type = intent.getStringExtra("type");
String name = intent.getStringExtra("object");
Log.d("NOTIFICATION", "NOME: " + name);
Log.d("NOTIFICATION", "ID: " + id);
Log.d("NOTIFICATION", "TYPE:" + type);
if (entering) {
Log.d(getClass().getSimpleName(), "entering");
}else {
Log.d(getClass().getSimpleName(), "exiting");
}
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(context, InterestPoint_Description.class);
notificationIntent.putExtra("id", id);
notificationIntent.putExtra("type", type);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = createNotification();
notification.setLatestEventInfo(context, "LisbonRoutes", "You are near " + name + ", touch here to check it out!", pendingIntent);
notificationManager.notify(Config.NOTIFICATION_ID, notification);
Config.NOTIFICATION_ID++;
}
private Notification createNotification() {
Notification notification = new Notification();
notification.icon = R.drawable.icon;
notification.when = System.currentTimeMillis();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.ledARGB = Color.WHITE;
notification.ledOnMS = 1500;
notification.ledOffMS = 1500;
return notification;
}
}
我希望我已经解释得很好:提前小号 感谢
“发送通知的正确的量,但他们都是。”他们都是什么? –
对不起,他们都是一样的,具有相同的文本,标题等:s – ralbuquerque