今天突然发现在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

Android 4.2 通知通过PendingIntent启动Activity失败的问题的更多相关文章

  1. 手把手教你_怎么找android应用的包名和启动activity

    自己主动化測试中常常遇到这个问题,关于这个题目,方法众多,咱的目的是找个比較简单靠谱的: 方法一: 先进入cmd窗体,adb shell 后: cd /data/data ls 能够看到包名了吧,缺点 ...

  2. Android应用程序内部启动Activity过程(startActivity)的源代码分析

    文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6703247 上文介绍了Android应用程序的 ...

  3. Android 面试必备 - 系统、App、Activity 启动过程“一锅端”

    Android 系统启动过程 从系统层看: linux 系统层 Android系统服务层 Zygote 从开机启动到Home Launcher: 启动bootloader (小程序:初始化硬件) 加载 ...

  4. Android开机启动Activity或者Service方法

    本文出自 “Bill_Hoo专栏” 博客,请务必保留此出处http://billhoo.blog.51cto.com/2337751/761230 这段时间在做Android的基础开发,现在有一需求是 ...

  5. Android四大组件之Activity详解——创建和启动Activity

    前面我们已经对Activity有过简单的介绍: Android开发——初始Activity Android开发——响应用户事件 Android开发——Activity生命周期 先来看一下最终结果 项目 ...

  6. Android Intent (可通过URL启动 Activity)

    Intent分为两大类: (1)显性的(Explicit) (2)隐性的(Implicit) 对于隐性意图,在某些时候, 应用程序只是想启动具有某种特征的组件, 并不想和某个特定的组件耦合. 使用In ...

  7. Android,配置Activity为启动Activity(AndroidManifest.xml,application,intent-filter,MAIN,LAUNCHER)

    备忘: 将Activity注册为启动Activity. 在AndroidManifest.xml中的<application>元素中加入以下<activity>子元素内容: & ...

  8. Android启动activity的4种模式(standard、singleTop、singleTask、singleINstance)

    在AndroidManifest.xml中配置activity时,android:launchMode属性会指定启动activity的模式,有四种: standard singleTop single ...

  9. android 25 跨进程启动activity

    跨进程启动activity,启动系统预定义的activity就是跨进程的. client项目启动server项目的activity. clientActivity.java package com.s ...

随机推荐

  1. 低字节序和高字节序相互转换(Little Endian/Big Endian)

    这个例子展示了如何转换整形数字的字节顺序,该方法可以用来在little-endian和big-endian之间转换. 说明:Windos(x86,x64)和Linux(x86,x64)都是little ...

  2. Web服务图片压缩,nginx+lua生成缩略图

    背景 目前而言,用移动端访问Web站点的用户越来越多,图片对流量的消耗是比较大的,之前一个用户用我们网站的app浏览的时候,2个小时耗去了2个G的流量,这是个很严重的问题,需要对图片进行压缩,减少对用 ...

  3. USACO5.4-TeleCowmunication

    题目大意:给出一个无向图,要求删除尽量少的点,使给定的2点间不再连通,并输出字典序最小的方案题型:图论-网络流此题难点在于建图,后面就是套网络流的模板.将点看成边,例如第i个点可以看成一条有向边< ...

  4. IE layout详解

    引言: Internet Explorer 中有很多奇怪的渲染问题可以给他一个”layout”得到解决,John Gallant 和 Holly Bergevin把他归类为“dimensional b ...

  5. jQuery之异步Ajax请求使用

    $.ajax({type:'',data:'',async:''...}) 参数: 1.cache: true缓存页面 false 不缓存页面 (默认: true,dataType为script和js ...

  6. jquery获取浏览器的高度和宽度

    <script type="text/javascript"> $(document).ready(function() { alert($(window).heigh ...

  7. 配置linux平台下基于vim的开发环境

    一.vim的基本配置 1.配置文件的位置在目录 /etc/ 下面,有个名为vimrc的文件,这是系统中公共的vim配置文件,对所有用户都有效.而在每个用户的主目录($HOME)下,都可以自己建立私有的 ...

  8. oldboy第五天学习

    一.生成器 列表生成器 >>> a [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> b = [] >>> for i in ...

  9. PHP之路——Apache启动失败查看日志

    windows下用运行 eventvwr--->windows日志--->应用程序日志-->软件

  10. UML类图标识

    矩形框:类 第一层:类名(抽象类用斜体). 第二层:属性(‘+’ 表示 public.‘-’ 表示 private.‘#’ 表示 protected). 第三层:方法. <<interfa ...