开发者

BOOT_COMPLETED receiver ActivityNotFoundException

I am trying to write an app that starts on boot up. My receiver works and my app is started on boot up, however it crashes because of ActivityNotFoundException. I may have messed up in the manifest somewhere. Please help to take a look.

This is the receiver code, LocationLock.class just does some stuff to lock the phone.

public class MyStartupIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent){
    Intent myStarterIntent = new Intent(context, LocationLock.class);
    myStarterIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(myStarterIntent);
}
}

This is the manifest:

<?xml version="1.0" encoding="utf-8"?>

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".LocationLock$Controller"
              android:label="@string/app_name_controller">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name=".LocationLock"
        android:label="@string/app_name"
        android:permission="android.permission.BIND_DEVICE_ADMIN">
        <meta-data android:name="android.app.device_admin"
                   android:resource="@xml/device_admin" />
        <intent-filter>
            <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
        </intent-filter>
    </receiver>
    <receiver android:name=".MyStartupIntentReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />      
        </intent-filter>
    </receiver>
</application>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

</manifest>

Below are the errors:

05-03 02:54:55.301: ERROR/AndroidRuntime(264): FATAL EXCEPTION: main
05-03 02:54:55.301: ERROR/AndroidRuntime(264): java.lang.RuntimeException: Unable to start receiver org.example.locationlock.MyStartupIntentReceiver: android.content.ActivityNotFoundException: Unable to find explicit activity class {org.example.locationlock/org.example.locationlock.LocationLock}; have you declared this activity in your AndroidManifest.xml?
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2821)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.app.ActivityThread.access$3200(ActivityThread.java:125)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2083)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.os.Looper.loop(Looper.java:123)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at java.lang.reflect.Method.invokeNative(Native Method)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at java.lang.reflect.Method.invoke(Method.java:521)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-03 02:54:55.301: ERR开发者_C百科OR/AndroidRuntime(264):     at dalvik.system.NativeStart.main(Native Method)
05-03 02:54:55.301: ERROR/AndroidRuntime(264): Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {org.example.locationlock/org.example.locationlock.LocationLock}; have you declared this activity in your AndroidManifest.xml?
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1404)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.app.ContextImpl.startActivity(ContextImpl.java:622)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.content.ContextWrapper.startActivity(ContextWrapper.java:258)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at org.example.locationlock.MyStartupIntentReceiver.onReceive(MyStartupIntentReceiver.java:12)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810)
05-03 02:54:55.301: ERROR/AndroidRuntime(264):     ... 10 more

Maybe I can't have two receivers listed one after another, but the MyStartupIntentReceiver has no activity associated with it.

Any help is much appreciated!


you are trying to start a receiver class: Intent myStarterIntent = new Intent(context, LocationLock.class);, since in the manifest file it is declared as a reciever class: <receiver android:name=".LocationLock" so modify this declaration to activiy:

<activity
    android:name=".LocationLock"
    android:windowSoftInputMode="stateVisible|adjustResize" >
</activity>


have you tried defining it as an activity in your manifest?

for example, within your section:

<activity android:name=".MyStartupIntentReceiver"
          android:launchMode="singleTop"
          android:screenOrientation="portrait"
          android:noHistory="true" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜