1

The BootReceiver never called even if the system was boot up using this command:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n com.android.canbedeleted.test/.BootReceiver

Permission I have put in the manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.android.canbedeleted.test">
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:label="test">
<receiver android:name="test.Droid.BootReceiver">
  <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
  </intent-filter>
</receiver>
</application>

The receiver tag i have tried removed it but don't see any different.

[BroadcastReceiver]
[IntentFilter (new string[] { Intent.ActionBootCompleted }, Priority = (int)IntentFilterPriority.HighPriority)]
public class BootReceiver : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent)
    { 
        System.Diagnostics.Debug.WriteLine ("*********************************** Broadcast Received *********************************");
        Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
        //Intent message = new Intent();
        //message.AddFlags(ActivityFlags.NewTask);
        //message.SetClass(context, typeof(KeyboardService));
        //context.StartService(intent);
    }
}

Even if I tried to type the cmd like this, i will have stack trace as below. The test.Droid is the namespace of the class.

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n com.android.canbedeleted.test/test.Droid.BootReceiver

StackTrace

Java.Lang.RuntimeException: Unable to instantiate receiver test.Droid.BootReceiver: java.lang.ClassNotFoundException: Didn't find class "test.Droid.BootReceiver" on path: DexPathList[[zip file "/data/app/com.android.canbedeleted.test-8.apk"],nativeLibraryDirectories=[/data/app-lib/com.android.canbedeleted.test-8, /vendor/lib, /system/lib]] ---> Java.Lang.ClassNotFoundException: Didn't find class "test.Droid.BootReceiver" on path: DexPathList[[zip file "/data/app/com.android.canbedeleted.test-8.apk"],nativeLibraryDirectories=[/data/app-lib/com.android.canbedeleted.test-8, /vendor/lib, /system/lib]] at java.lang.ClassNotFoundException: Didn't find class "test.Droid.BootReceiver" on path: DexPathList[[zip file "/data/app/com.android.canbedeleted.test-8.apk"],nativeLibraryDirectories=[/data/app-lib/com.android.canbedeleted.test-8, /vendor/lib, /system/lib]] at at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67) at at java.lang.ClassLoader.loadClass(ClassLoader.java:497) at at java.lang.ClassLoader.loadClass(ClassLoader.java:457) at at android.app.ActivityThread.handleReceiver(ActivityThread.java:2513) at at android.app.ActivityThread.access$1800(ActivityThread.java:161) at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341) at at android.os.Handler.dispatchMessage(Handler.java:102) at at android.os.Looper.loop(Looper.java:157) at at android.app.ActivityThread.main(ActivityThread.java:5356) at at java.lang.reflect.Method.invokeNative(Native Method) at at java.lang.reflect.Method.invoke(Method.java:515) at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at at dalvik.system.NativeStart.main(Native Method) --- End of inner exception stack trace --- at java.lang.RuntimeException: Unable to instantiate receiver test.Droid.BootReceiver: java.lang.ClassNotFoundException: Didn't find class "test.Droid.BootReceiver" on path: DexPathList[[zip file "/data/app/com.android.canbedeleted.test-8.apk"],nativeLibraryDirectories=[/data/app-lib/com.android.canbedeleted.test-8, /vendor/lib, /system/lib]] at at android.app.ActivityThread.handleReceiver(ActivityThread.java:2518) at at android.app.ActivityThread.access$1800(ActivityThread.java:161) at at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1341) at at android.os.Handler.dispatchMessage(Handler.java:102) at at android.os.Looper.loop(Looper.java:157) at at android.app.ActivityThread.main(ActivityThread.java:5356) at at java.lang.reflect.Method.invokeNative(Native Method) at at java.lang.reflect.Method.invoke(Method.java:515) at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265) at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081) at at dalvik.system.NativeStart.main(Native Method) at Caused by: java.lang.ClassNotFoundException: Didn't find class "test.Droid.BootReceiver" on path: DexPathList[[zip file "/data/app/com.android.canbedeleted.test-8.apk"],nativeLibraryDirectories=[/data/app-lib/com.android.canbedeleted.test-8, /vendor/lib, /system/lib]] at at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67) at at java.lang.ClassLoader.loadClass(ClassLoader.java:497) at at java.lang.ClassLoader.loadClass(ClassLoader.java:457) at at android.app.ActivityThread.handleReceiver(ActivityThread.java:2513) at ... 10 more

Prashant Cholachagudda
  • 13,012
  • 23
  • 97
  • 162
LittleFunny
  • 8,155
  • 15
  • 87
  • 198
  • Take a look at http://stackoverflow.com/questions/39713862/xamarin-form-android-doesnt-received-the-broadcast-after-reboot/39714163#39714163 – SushiHangover Oct 13 '16 at 00:13
  • I never force the application to close. I even have the activity showing on screen – LittleFunny Oct 13 '16 at 00:17
  • Look at your *generated* manifest and the class names that is actually contains. – SushiHangover Oct 13 '16 at 00:23
  • 1
    Now it works.. not sure is it because I haven't put the namespace on the manifest in the receiver tag. Now when I tapped in the command, the receiver receive the intent before and after the phone reboot. – LittleFunny Oct 13 '16 at 01:31

2 Answers2

1

Please remove the receiver in your AndroidManifest.xml. You don't have to declare it there if you are using attributes like BroadcastReceiver and IntentFilter. Else the generated manifest (\obj\Debug\android\AndroidManifest.xml) will contain two declarations of the receiver and this might cause some issues. Using the attributes has the advantage, that you don't have to care about the correct class names.

Sven-Michael Stübe
  • 14,560
  • 4
  • 52
  • 103
0

This com.android.canbedeleted.test/test.Droid.BootReceiver may not be correct.

With the 5.0 release, the default package names for Android Callable Wrappers will be based on the MD5SUM of the assembly-qualified name of the type being exported. This allows the same fully-qualified name to be provided from two different assemblies and not get a packaging error.

Check what is the generated BootReceiver name, under your project's \obj\Debug\android\AndroidManifest.xml file.

Read more about Android Callable Wrapper Naming topic here

Prashant Cholachagudda
  • 13,012
  • 23
  • 97
  • 162