Android运行时错误(仅限真实设备):SecurityException

时间:2013-12-17 04:57:46

标签: android android-build

该应用程序可在我的Genymotion模拟器上运行,但在启动时出现此异常时在真实设备上运行时会失败:

Launching application: <package>/<package>.MainActivity.
DEVICE SHELL COMMAND: am start -D -n "<package>/<package>.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=<package>/.MainActivity }
java.lang.SecurityException: Permission Denial: starting Intent { act=<package>.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=<package>/.MainActivity } from null (pid=21943, uid=2000) not exported from uid 10204
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:2204)
at com.android.commands.am.Am.runStart(Am.java:494)
at com.android.commands.am.Am.run(Am.java:109)
at com.android.commands.am.Am.main(Am.java:82)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:243)
at dalvik.system.NativeStart.main(Native Method)

Waiting for process: <package>

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="<package>"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="<package>.MainActivity"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>

和MainActivity.java:

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

}

发生了什么事?当我使用正常配置时,为什么要尝试以特定用户身份运行?

2 个答案:

答案 0 :(得分:2)

menifest.xml文件

中更改以下内容
<activity
     android:name="<package>.MainActivity"
     android:label="@string/app_name" >
<intent-filter>
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

答案 1 :(得分:0)

您应该在清单

中定义您的活动
       <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@android:style/AppTheme" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>