无法在 Android Intent 中接收额外内容
Unable to receive extras in Android Intent
GCMIntTentService.java
if (intent.getStringExtra("request") != null
&& !intent.getStringExtra("request").equalsIgnoreCase("null")){
String message = intent.getStringExtra("request");
String cardNo = intent.getStringExtra("requestCardNumber");
String amount = intent.getStringExtra("requestAmount");
String cardHoldername = intent.getStringExtra("requestHoldername");
// This is how to get values from the push message (data)
long timestamp = intent.getLongExtra("timestamp", -1);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.logofinal,
"App Notification", System.currentTimeMillis());
Intent notificationIntent = new Intent(context, Fund_Transfer.class);
notificationIntent.putExtra("request", message);
notificationIntent.putExtra("requestCardNumber", cardNo);
notificationIntent.putExtra("requestAmount", amount);
notificationIntent.putExtra("requestHoldername", cardHoldername);
/*
* notificationIntent.putExtra("mobile", mob);
* notificationIntent.putExtra("desc", desc);
* notificationIntent.putExtra("amt", amt);
*/
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
note.setLatestEventInfo(context, "DvPay Notification", message,
pendingIntent);
note.defaults |= Notification.DEFAULT_SOUND;
note.defaults |= Notification.DEFAULT_VIBRATE;
note.defaults |= Notification.DEFAULT_LIGHTS;
note.flags |= Notification.FLAG_AUTO_CANCEL;
sendGCMIntent(context, message,cardNo,amount,cardHoldername);
notificationManager.notify(0, note);
}
}
private void sendGCMIntent(Context ctx, String message,String requestCardNumber, String requestAmount, String requestHoldername) {
Intent broadcastIntent = new Intent();
broadcastIntent.setAction("GCM_RECEIVED_ACTION");
broadcastIntent.putExtra("request", message);
broadcastIntent.putExtra("requestCardNumber", requestCardNumber);
broadcastIntent.putExtra("requestAmount", requestAmount);
broadcastIntent.putExtra("requestHoldername", requestHoldername);
ctx.sendBroadcast(broadcastIntent);
}
Fund_Transfer.java
if(bundle.getString("request")!=null && !bundle.getString("request").equalsIgnoreCase("") && !bundle.getString("request").equalsIgnoreCase("null")){
String message = bundle.getString("request");
System.out.println("-------------------Notification message---------"+message);
String tempCard = bundle.getString("requestCardNumber");
String name = bundle.getString("requestHoldername");
String amount = bundle.getString("requestAmount");
edtamt.setText(amount);
payeeName.setVisibility(View.VISIBLE);
cardHolder.setText(name);
card = tempCard;
System.out.println("-----------------------------------"+card);
}
我正在从 GCMIntentService class 中的通知中发送额外内容,但我不明白问题出在哪里。我能够收到名为 "request" 的字符串,但无法在我的资金转账中收到其他字符串 class.I 已在调试器中对其进行检查,值已正确传递给 Fund_Transfer class。
得到我的答案这条线给我带来了问题
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
改为
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_ONE_SHOT);
GCMIntTentService.java
if (intent.getStringExtra("request") != null
&& !intent.getStringExtra("request").equalsIgnoreCase("null")){
String message = intent.getStringExtra("request");
String cardNo = intent.getStringExtra("requestCardNumber");
String amount = intent.getStringExtra("requestAmount");
String cardHoldername = intent.getStringExtra("requestHoldername");
// This is how to get values from the push message (data)
long timestamp = intent.getLongExtra("timestamp", -1);
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.logofinal,
"App Notification", System.currentTimeMillis());
Intent notificationIntent = new Intent(context, Fund_Transfer.class);
notificationIntent.putExtra("request", message);
notificationIntent.putExtra("requestCardNumber", cardNo);
notificationIntent.putExtra("requestAmount", amount);
notificationIntent.putExtra("requestHoldername", cardHoldername);
/*
* notificationIntent.putExtra("mobile", mob);
* notificationIntent.putExtra("desc", desc);
* notificationIntent.putExtra("amt", amt);
*/
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
note.setLatestEventInfo(context, "DvPay Notification", message,
pendingIntent);
note.defaults |= Notification.DEFAULT_SOUND;
note.defaults |= Notification.DEFAULT_VIBRATE;
note.defaults |= Notification.DEFAULT_LIGHTS;
note.flags |= Notification.FLAG_AUTO_CANCEL;
sendGCMIntent(context, message,cardNo,amount,cardHoldername);
notificationManager.notify(0, note);
}
}
private void sendGCMIntent(Context ctx, String message,String requestCardNumber, String requestAmount, String requestHoldername) {
Intent broadcastIntent = new Intent();
broadcastIntent.setAction("GCM_RECEIVED_ACTION");
broadcastIntent.putExtra("request", message);
broadcastIntent.putExtra("requestCardNumber", requestCardNumber);
broadcastIntent.putExtra("requestAmount", requestAmount);
broadcastIntent.putExtra("requestHoldername", requestHoldername);
ctx.sendBroadcast(broadcastIntent);
}
Fund_Transfer.java
if(bundle.getString("request")!=null && !bundle.getString("request").equalsIgnoreCase("") && !bundle.getString("request").equalsIgnoreCase("null")){
String message = bundle.getString("request");
System.out.println("-------------------Notification message---------"+message);
String tempCard = bundle.getString("requestCardNumber");
String name = bundle.getString("requestHoldername");
String amount = bundle.getString("requestAmount");
edtamt.setText(amount);
payeeName.setVisibility(View.VISIBLE);
cardHolder.setText(name);
card = tempCard;
System.out.println("-----------------------------------"+card);
}
我正在从 GCMIntentService class 中的通知中发送额外内容,但我不明白问题出在哪里。我能够收到名为 "request" 的字符串,但无法在我的资金转账中收到其他字符串 class.I 已在调试器中对其进行检查,值已正确传递给 Fund_Transfer class。
得到我的答案这条线给我带来了问题
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
改为
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
notificationIntent, PendingIntent.FLAG_ONE_SHOT);