我在phonegap 5.0中有一个App构建,它还有一个触发通知的后台服务。一切正常,但是当我点击通知时,应用程序会打开,但我无法从通知中获取任何参数。在phonegap中,我使用此local.notification.plugin从本地通知获取信息,但仅在从应用程序添加通知而不是从后台服务添加通知时才有效。
有没有我错过的东西?有没有人有同样的问题?
这是我的Android服务代码:
public class MyService extends BackgroundService {
private void showNotification(int _nid, String _id, Date _now, String contentTitle, String contentText) {
_log=_log+_now.toString()+" activada notificacion"+contentTitle;
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.icon)
.setContentTitle(contentTitle)
.setContentText(contentText);
int NOTIFICATION_ID = _nid;
Uri alarmSound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification_sound);
builder.setSound(alarmSound);
builder.setSmallIcon(R.drawable.notification_icon);
if(_id.equals("0")){
}else{
File theImg = new File("https://s3-sa-east-1.amazonaws.com/iloveit/promo/" + _id + ".jpg");
if(!theImg.exists()) {
builder.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(getBitmapFromURL("https://s3-sa-east-1.amazonaws.com/iloveit/promo/" + _id + ".jpg")));
}
}
//builder.setLargeIcon(getBitmapFromURL("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQhp07tKX-yadhAnHJXd5_oxHMtbYBhxvOeLqsEypSdFq5zThwiLg"));
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(
this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, builder.build());
}}