我已经在我的 phonegap 应用程序中实现了 Google Cloud Messaging,但是在单击状态栏中的 gcm 通知后,我必须在对话框或警报框中显示一条消息。我用谷歌搜索了它,但什么也做不了。GCMIntentService.java
@Override
public void onUnregistered(Context context, String regId) {
Log.d(TAG, "onUnregistered - regId: " + regId);
}
@Override
protected void onMessage(final Context arg0, final Intent arg1) {
// TODO Auto-generated method stub
Log.i("Registration", "Got a message!");
Log.i("Registration", arg1.getStringExtra("message"));
String message = arg1.getStringExtra("message");
generateNotification(getApplicationContext(), message);
}
private static void generateNotification(Context context, String message) {
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.tbgicon, message, when);
Intent notificationIntent = new Intent(context, KBJphoneGAP.class);
notificationIntent.putExtra("message", message);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
String title = "The Business Game";
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults|= Notification.DEFAULT_LIGHTS;
notification.defaults|= Notification.DEFAULT_VIBRATE;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notificationManager.notify(0, notification);
}
这是我在 phonegap 中的 MainActivity.java
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
// super.loadUrl(Config.getStartUrl());
super.setIntegerProperty("splashscreen", R.drawable.splashscreen);
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
super.loadUrl("file:///android_asset/www/index.html", 11000);
}
请任何人帮助我解决这个问题,我已经尝试在 onMessage 方法中使用 alertdialog 框,但在收到通知后应用程序正在停止。