我正在使用BroadCast Listener监听来电统计信息,然后像这样推送通知:
CharSequence contentTitle = "Contact: " + number;
CharSequence contentText = "Call From: " + number;
Intent notificationIntent = new Intent(context, CallHandler.class);
notificationIntent.putExtra(KEYS.NUMBER, number);
notificationIntent.putExtra(KEYS.STATE, stat);
notificationIntent.putExtra(KEYS.NAME, name);
notificationIntent.putExtra(KEYS.DURATION, duration);
notificationIntent.putExtra(KEYS.START_TIME, startTime);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notif.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify((int) System.currentTimeMillis(), notif);因此,当有多个呼叫时,我希望有多个呼叫通知,当我单击每个通知时,我希望启动一个带有附加参数的活动。但是,我可以看到后面开始的活动得到了前一个调用的意图。
下面是我从活动中寻找意图的方法
Bundle extras = getIntent().getExtras();
String number = extras.getString(KEYS.NUMBER);
// String state = extras.getString(KEYS.STATE);
long duration = extras.getLong(KEYS.DURATION);
Date start = getStartDate();
((TextView) findViewById(R.id.subject)).setText("");
((TextView) findViewById(R.id.start_time)).setText(tf.format(start));
((TextView) findViewById(R.id.end_time)).setText(tf
.format(getEndDate()));
((TextView) findViewById(R.id.caller_number)).setText(number);
((TextView) findViewById(R.id.notes)).setText(getNotesDefaultContent(
number, duration, start));我如何保持意图分离,调用独立的活动?
发布于 2011-02-16 15:36:27
试试这个:
PendingIntent.getActivity(context, 0 , notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);注意PendingIntent.getActitity方法的最后一个参数。如果您想知道应该使用哪个标志,请参阅API文档- [http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context](http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context),int,android.content.Intent,int)
1:http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context
~多尔夫~
发布于 2013-03-01 18:56:14
它可以更容易地实现……只需覆盖activity类中的onNewIntent(Intent intent)方法,并在其中添加startactivity(intent)即可。
发布于 2010-12-22 15:00:35
好的,我想我找到了一个解决方案。诀窍是正确地创建意图!
以下是我的工作代码:
CharSequence contentTitle = "Contact: " + number;
CharSequence contentText = "Call From: " + number;
Intent notificationIntent = new Intent(context, CallHandler.class);
notificationIntent.setAction("com.vantage.vcrm.android.telephony"+System.currentTimeMillis());//unique per contact
notificationIntent.putExtra(KEYS.NUMBER, number);
notificationIntent.putExtra(KEYS.STATE, stat);
notificationIntent.putExtra(KEYS.NAME, name);
notificationIntent.putExtra(KEYS.DURATION, duration);
notificationIntent.putExtra(KEYS.START_TIME, startTime);
PendingIntent contentIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), notificationIntent, 0);
notif.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify((int) System.currentTimeMillis(), notif);你看,我通过这样做在我的意图中设置了唯一的动作:
notificationIntent.setAction("com.vantage.vcrm.android.telephony"+System.currentTimeMillis());//unique per contact另外,我在待定意向书中发送唯一的请求者ID:
PendingIntent.getActivity(context, (int) System.currentTimeMillis(), notificationIntent, 0);这解决了问题。
https://stackoverflow.com/questions/4472447
复制相似问题