xml里面名称错了,少了个r,是BootReceiver 不是BootReceive
<receiver android:name=".BootReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:name=".BootReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>java.lang.RuntimeException:
Unable to instantiate receiver MyName.MyName.BootReceiver: java.lang.ClassNotFoundException:
MyName.MyName.BootReceiver
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="16" />
<application android:icon="@drawable/Icon" android:persistent="true">
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
</manifest>
仅需在BroadcastReceiver中直接写入
[IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]
即可注册成功可以正常触发BootReceiver.cs [BroadcastReceiver]
[IntentFilter(new[] { Android.Content.Intent.ActionBootCompleted })]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
}
}