How to get Intent from PendingIntent

[亡魂溺海] 提交于 2020-01-14 07:02:42

问题


Can I get the Intent from a PendingIntent?

Here is the scenario:

  1. I create an Intent (let's call it myIntent)
  2. I put some Extra information with a String (call it myInfo)
  3. I create a PendingIntent (myPendingIntent) using myIntent
  4. I set an alarm using the AlarmManager and myPendingIntent
  5. At a later stage I get hold of the PendingIntent using PendingIntent.getBroadcast
  6. At that point I want to read myInfo from myIntent which is in myPendingIntent

Is this possible? By looking around Google, I am coming close to the conclusion that this is not possible.


回答1:


Is this possible?

Nope. PendingIntent is a write-only interface. You can replace the Intent, but you cannot read it.




回答2:


It's possible since 4.2.2 using reflection. Take a look at this answer, there's complete solution to obtain Intent from PendingIntent.



来源:https://stackoverflow.com/questions/23725035/how-to-get-intent-from-pendingintent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!