我正在使用 phonegap 开发一个 android 应用程序。我想从通知栏启动应用程序。虽然这可能是一个重复的问题,但似乎没有什么对我有用;我尝试过的链接很少。
http://pilhuhn.blogspot.in/2010/12/pitfall-in-pendingintent-with-solution.html
从此链接开发的独立应用程序正在运行,但是当我与我的真实项目集成时,点击通知栏什么也没做,下面是我的代码
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,"Message received", System.currentTimeMillis());
notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL;
Intent intent = new Intent(context, MyClass.class);
intent.putExtra("message", message);
intent.putExtra("shortMsg", shortMsg);
intent.putExtra("source", source);
intent.putExtra("phone", phone);
intent.putExtra("datetime", datetime);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(context, "Message", "New message received", pendingIntent);
notificationManager.notify(0, notification);
MyClass.class 代码,
Bundle extras = getIntent().getExtras();
if (extras != null)
{
System.out.println("in extras");
//Retrive data from the intent and store them in instance variables
this.message = extras.getString("message");
this.shortMsg = extras.getString("shortMsg");
this.source = extras.getString("source");
this.phone = extras.getString("phone");
this.datetime = extras.getString("datetime");
}
提前致谢,
七无