Cannot deploy to my android device


#1

Hi all, I’m trying to deploy the sample QuizActivity to my phone and I get the following error: (note: I’m using Android Studio instead of Eclipse)

Launching application: com.example.jmorales.quizactivity/com.example.jmorales.quizactivity.QuizActivity.
DEVICE SHELL COMMAND: am start -n “com.example.jmorales.quizactivity/com.example.jmorales.quizactivity.QuizActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.jmorales.quizactivity/.QuizActivity }
java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.jmorales.quizactivity/.QuizActivity } from null (pid=23543, uid=2000) not exported from uid 10197
at android.os.Parcel.readException(Parcel.java:1474)
at android.os.Parcel.readException(Parcel.java:1428)
at android.app.ActivityManagerProxy.startActivityAsUser(ActivityManagerNative.java:2311)
at com.android.commands.am.Am.runStart(Am.java:680)
at com.android.commands.am.Am.onRun(Am.java:270)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.am.Am.main(Am.java:76)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:285)
at dalvik.system.NativeStart.main(Native Method)

I’ve enabled debugging on the phone and it shows the App in ‘Developer Options > Select debug app’.

Reading this exception it appears that Android is denying the request to launch the app with the QuizActivity, but why? What is the workflow to troubleshoot exactly what is causing the intent to get denied. How does one triage these security errors? Could it be my phone/setup? I’m on a mac using a HTC m8

The project does load fine in the nexus emulator:

Launching application: com.example.jmorales.quizactivity/com.example.jmorales.quizactivity.QuizActivity.
DEVICE SHELL COMMAND: am start -n “com.example.jmorales.quizactivity/com.example.jmorales.quizactivity.QuizActivity” -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.jmorales.quizactivity/.QuizActivity }


#2

so for the poor soul that runs into this same issue, the fix was that It turns out that my activity wasn’t able to be started because it didn’t advertise the intent of being a main activity. It was originally:

        <activity
            android:name="QuizActivity"
            android:label="@string/title_activity_quiz"
            >
        </activity>

Not sure why this worked in the emulator, but simply adding android:exported="true" to the activity element fixed it. i.e.

<activity android:name="QuizActivity" android:label="@string/title_activity_quiz" android:exported="true" > </activity> I could have probably also added the MainActivity intent-filter as well.

It’s a hard way to learn about intents and filters.