所以这是我的代码,它设置通过缩放服务调用用户的通知。但是,如果用户未单击通知,而只是直接点击应用程序图标,则无法正确捕获其他内容。我对如何在简历中从这个未决意图中提取额外内容感到有点迷失。
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); //构建新通知 mBuilder.setSmallIcon(R.drawable.ic_launcher); mBuilder.setContentTitle(的getString(R.string.incoming_zoom_meeting_title)); mBuilder.setContentText(String.format(getString(R.string.incoming_zoom_meeting_message),pushObject.getZoomCall()。get(CIConstants.ZOOM_TITLE))); mBuilder.setSound(Uri.parse(“android.resource://”+ this.getPackageName()+“/”+ R.raw.constellation)); //设置要播放的声音
Intent resultIntent = new Intent(this, MainActivity.class); //set notification click behavior
resultIntent.putExtra(CIConstants.ZOOM_MEETING_ID, pushObject.getZoomCall().getString(CIConstants.ZOOM_MEETING_ID).trim());
resultIntent.putExtra(CIConstants.ZOOM_USER_ID,pushObject.getZoomCall().get(CIConstants.ZOOM_TITLE).toString());
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
int mNotificationId = 001;
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());
然后通过。
在主要活动中重新启动 if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
mMeetingNumber = extras != null ? extras.get(CIConstants.ZOOM_MEETING_ID).toString() : null;
mMeetingCallerName = extras != null ? extras.get(CIConstants.ZOOM_USER_ID).toString() : null;
//if there is a meeting id in the intent
mZoomCallIncoming = mMeetingNumber != null && !mMeetingNumber.isEmpty();
}
非常感谢任何帮助= D。
答案 0 :(得分:0)
如果有人发现这种情况,最简单的方法是继续将其放入一个静态变量中以便稍后在onResume中检索,以防用户没有点击通知它将在onResume上填充
Intent i = getIntent();
String meetingId = i.getStringExtra(CIConstants.ZOOM_MEETING_ID_KEY);
String userId = i.getStringExtra(CIConstants.ZOOM_USER_ID_KEY);
if (meetingId != null && !meetingId.isEmpty()) {
CIConstants.ZOOM_MEETING_ID = meetingId;
CIConstants.ZOOM_CALL_INCOMING = true;
i.putExtra(CIConstants.ZOOM_MEETING_ID_KEY, "");
i.putExtra(CIConstants.ZOOM_USER_ID_KEY, "");
}
if (userId != null && !userId.isEmpty())
CIConstants.ZOOM_USER_ID = userId;
if (CIConstants.ZOOM_CALL_INCOMING) {
if(!CIConstants.ZOOM_CALL_NOTIFICATION_SOUND_PLAYING) {
NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSound(Uri.parse("android.resource://" + this.getPackageName() + "/" + R.raw.constellation));
manager.notify("", CIUtility.NOTIFICATION_ZOOM, builder.build());
}
createZoomCallDialogue(CIConstants.ZOOM_MEETING_ID, CIConstants.ZOOM_USER_ID);
CIConstants.ZOOM_CALL_INCOMING = false; //reset the zoom uri so that it is not called again when activity is resumed from zoom
CIConstants.ZOOM_CALL_NOTIFICATION_SOUND_PLAYING = false;
CIConstants.ZOOM_MEETING_ID = null;
CIConstants.ZOOM_USER_ID = null;
}