2016-11-14 118 views
3

我得到NotificationListenerService来拦截通知并清除,然后想拦截保存到数据库的PendingIntent的通知,但是PendingIntent没有序列化,所以我想获取PendingIntend内部的Intent,然后使用intent.toUri()如何将PendingIntent保存到SQLite数据库?

Process: com.example.joee.cleardatademo, PID: 20441 
        java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW flg=0x14008000 cmp=com.skype.raider/com.skype.android.app.main.HubActivity (has extras) } from ProcessRecord{4596be88 20441:com.example.joee.cleardatademo/u0a1647} (pid=20441, uid=11647) not exported from uid 11028 
         at android.os.Parcel.readException(Parcel.java:1474) 
         at android.os.Parcel.readException(Parcel.java:1427) 
         at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2104) 
         at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419) 
         at android.app.ContextImpl.startActivity(ContextImpl.java:1065) 
         at android.app.ContextImpl.startActivity(ContextImpl.java:1047) 
         at com.example.joee.cleardatademo.activity.NotificationManagerActivity$2$1.onClick(NotificationManagerActivity.java:110) 
         at android.view.View.performClick(View.java:4569) 
         at android.view.View$PerformClick.run(View.java:18570) 
         at android.os.Handler.handleCallback(Handler.java:733) 
         at android.os.Handler.dispatchMessage(Handler.java:95) 
         at android.os.Looper.loop(Looper.java:212) 
         at android.app.ActivityThread.main(ActivityThread.java:5151) 
         at java.lang.reflect.Method.invokeNative(Native Method) 
         at java.lang.reflect.Method.invoke(Method.java:515) 
         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684) 
         at dalvik.system.NativeStart.main(Native Method) 
I/Process: Sending signal. PID: 20441 SIG: 9 
Disconnected from the target VM, address: 'localhost:8633', transport: 'socket' 

我怎么能保存的PendingIntent到数据库或其他方法:序列化保存到数据库中,但是这时候有一个问题,当我调用startActivity(意向)后失步而意向时,有一个例外的方法要实现和保存PendingIntent效果一样吗?

+0

您是否找到了将其保存到数据库并检索以启动应用程序的方法? – Libin

回答

1

我想你误会了pu PendingIntent。它应该用于激发它在应用程序中包含的Intent,与原始应用程序不同,但具有相同的权限。这就是你如何启动其他应用程序内部的活动。

它的方式是通过Android中的绑定器机制与原始目标建立连接。即使将PendingIntent保存为Parcel,但如果将PendingIntent恢复为原来的对象,它将保留与原始对象的连接,因为它会保存连接令牌。

但是,您所做的是从PendingIntent中撕下Intent并尝试启动它。它会尝试从原始应用程序启动一项您无权访问的活动。不幸的是,我没有办法让您将PendingIntent保存到数据库中,因为您需要保存我提到的令牌,并且没有可靠的方法来获取它。它甚至不存储在Java代码中。