今天突然发现在Android 4.2手机上点击通知消息无法打开Activity的问题,具体Logcat信息如下:

01-09 11:37:43.733: WARN/ActivityManager(92): Unable to send startActivity intent
java.lang.SecurityException: Permission Denial: starting Intent { flg=0x10800000
cmp=org.goodev/.activities.ProjectActivity
bnds=[254,64][466,140] } from null (pid=-1, uid=10073) requires null
at
com.android.server.am.ActivityStack.startActivityLocked(ActivityStack.java:1973)
at
com.android.server.am.ActivityManagerService.
startActivityInPackage(ActivityManagerService.java:2271)
at
com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:212)
at
com.android.server.am.ActivityManagerService.
startActivityIntentSender(ActivityManagerService.java:2134)
at
android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:211)
at
com.android.server.am.ActivityManagerService.
onTransact(ActivityManagerService.java:1467)
at android.os.Binder.execTransact(Binder.java:320)
at dalvik.system.NativeStart.run(Native Method)

值得注意的地方用红色标示了。

研究了一下发现,该问题应该是4.2关于安全加强控制导致的。 解决该问题比较简单,在 AndroidManifest.xml 文件中 该Activity声明的地方 添加一个 “android:exported=”true”” 属性即可。

也就是说 在4.2系统中无法从外部启动一个没有exported的Activity。 而通过PendingIntent启动Activity, 启动源为系统,和被启动的应用不是一个PID。

关于exported属性的解释如下:

android:exportedWhether or not the activity can be launched by components of other applications — “true” if it can be, and “false” if not. If “false“, the activity can be launched only by components of the
same application or applications with the same user ID.

The default value depends on whether the activity contains intent
filters. The absence of any filters means that the activity can be
invoked only by specifying its exact class name. This implies that the
activity is intended only for application-internal use
(since others would not know the class name). So in this case, the
default value is “false“. On the other hand, the presence
of at least one filter implies that the activity is intended for
external use, so the default value is “true“.

This attribute is not the only way to limit an activity’s exposure to
other applications. You can also use a permission to limit the external
entities that can invoke the activity (see the permission attribute).

详细信息参考:http://developer.android.com/guide/topics/manifest/activity-element.html#exported

最新文章

  1. 日志系统实战(三)-分布式跟踪的Net实现
  2. python 跨语言数据交互、json、pickle(序列化)、urllib、requests(爬虫模块)、XML。
  3. 客户端安全-csrf
  4. 两个不等式(Nopier)
  5. asp.net将内容导出到Excel,Table表格数据(html)导出EXCEL
  6. 跟随标准与Webkit源码探究DOM -- 获取元素之getElementById
  7. cocos2d-x 3.2读取xml和json练习
  8. Markdown简短教程
  9. Android窗口管理服务WindowManagerService的简要介绍和学习计划
  10. Android设置背景
  11. 轻量级IOC框架Guice
  12. ev=ev || window.event 与 ev = window.event || ev 区别
  13. (转载)java基础:关于java流与文件操作
  14. miniui 给表格行添加监听事件的几种方法以及点击某列列名数据不能排序的问题
  15. pytthon—day8 读写模式的结合、文件操作模式、with完成文本文件复制、游标操作
  16. TCP/IP、UDP、HTTP、SOCKET详解
  17. Lvs Dr 模式配置
  18. 实战ELK(9) Elasticsearch地理位置
  19. NC 自定义项参照设置为查询条件
  20. xshell 利用密钥登录

热门文章

  1. MySQL where
  2. 五、C# 类
  3. Android学习----五大布局
  4. nodejs读取本地txt文件并输出到浏览器
  5. sublime3 插件pylinter的安装
  6. Jssdk微信分享
  7. NET Core 数据保护2
  8. codevs 2152 滑雪
  9. Solr4.8.0源码分析(2)之Solr的启动(一)
  10. protractor protractor.conf.js [launcher] Process exited with error code 1 undefined:1190