PendingIntent 的 onActivityResult
如何获取从NotificationManager启动的活动的结果?
换句话说,我需要从PendingIntent获取resultCode。
public void test(Context context){
Notification notification = new Notification(null, "text", System.currentTimeMillis());
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.example.com"));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
notification.setLatestEventInfo(context, "text", "text", pendingIntent);
notificationManager.notify(0, notification);
}
我希望在浏览器活动结束时收到通知。
OBS:此代码位于活动之外,因此它收到 上下文作为参数
How do i get the result of an activity started from NotificationManager?
In other words i need to get the resultCode from a PendingIntent.
public void test(Context context){
Notification notification = new Notification(null, "text", System.currentTimeMillis());
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.example.com"));
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
notification.setLatestEventInfo(context, "text", "text", pendingIntent);
notificationManager.notify(0, notification);
}
I want to be notified when the browser's activity ends.
OBS: This code is outside an activity, that's why it recieves the
context as parameter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您有设置
PendingIntent
的活动A
。此PendingIntent
调用活动B
。您想要接收B
的结果。您可以通过引入代理活动来做到这一点:
A
->PendingIntent
->ProxyActivity
-->startActivityForResult
-->B
。这样您就可以将来自B
的结果接收到您的ProxyActivity
活动中。请注意,您应该在
ProxyActivity.onCreate()
中调用startActivityForResult()
。Let's assume you have activity
A
that setsPendingIntent
. ThisPendingIntent
calls activityB
. You want receive result ofB
.You can do this by introducing proxy activity:
A
->PendingIntent
->ProxyActivity
-->startActivityForResult
-->B
. This way you'll receive result fromB
into yourProxyActivity
activity.Note that you should call
startActivityForResult()
inProxyActivity.onCreate()
.让我们简单地看一下,
在活动 A 中:
在活动 B 中:
Let's see in simply way ,
IN Activity A :
In Activity B: