我正在建立用户收到朋友请求的通知.通知有一个接受和拒绝按钮,根据用户点击的内容,启动的活动将处理请求.无论如何,当用户点击接受时,启动的活动应该收到标题为accept的请求,反之亦然.但是出于一些奇怪的原因,无论是单击“接受还是拒绝”,请求字符串都会返回拒绝.我甚至将拒绝请求字符串注释为发送接受或null,但它仍然返回下降.这太荒谬了.这就是我做的.
public voID newRequest(String name,String ID, String relation){ Intent intent = new Intent(this, Contacts.class); Bundle extras= new Bundle(); extras.putString("request", "accept"); extras.putString("relation", relation); extras.putString("name", name); extras.putString("ID", ID); Intent in = new Intent(this, Contacts.class); Bundle extra= new Bundle(); extra.putString("request", "decline"); extra.putString("relation", relation); extra.putString("name", name); extra.putString("ID", ID); intent.putExtras(extras); in.putExtras(extra); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); PendingIntent pIn = PendingIntent.getActivity(this, 0, in, 0); Notification noti = new NotificationCompat.Builder(this) .setContentTitle(name+" sent you have received a frIEnd request") .setContentText("Reflap").setSmallicon(R.drawable.fav) .setContentIntent(pIntent) .addAction(0, "Accept", pIntent) .addAction(0, "Decline", pIn) .build(); notificationmanager notificationmanager = (notificationmanager) getSystemService(NOTIFICATION_SERVICE); // HIDe the notification after its selected noti.flags |= Notification.FLAG_auto_CANCEL; notificationmanager.notify(5, noti); }
这是接收意图的活动
Intent intent=getIntent(); //username=intent.getStringExtra("username"); Bundle extras=intent.getExtras(); ///*if(extras.getString("request")!=null){ try{ requester=extras.getString("request"); senderID=extras.getString("ID"); namer=extras.getString("name"); relation=extras.getString("relation"); System.out.println("Starting to perform an accept with "+namer+" and user ID "+senderID+" and request is "+requester); }catch(Exception e){ e.printstacktrace(); }
但每次点击字符串的任何按钮都会返回拒绝.这真的很奇怪.
解决方法:
弄清楚了.问题出在这里
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); PendingIntent pIn = PendingIntent.getActivity(this, 0, in, 0);
两者请求代码相同.它需要与众不同.这有效:
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); PendingIntent pIn = PendingIntent.getActivity(this, 1, in, 0);
总结 以上是内存溢出为你收集整理的android – Bundle extra发送错误的字符串全部内容,希望文章能够帮你解决android – Bundle extra发送错误的字符串所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)