我正在尝试向BroadcastReceiver
上的Xamarin.Forms
项目添加Android
。每次启动此接收器,设备启动。我添加了这个C#
代码:
namespace SMSIP2.Droid
{
[BroadcastReceiver]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
class BootReceiver : BroadcastReceiver
{
public BootReceiver()
{
}
public override void OnReceive(Context context, Intent intent)
{
Toast.MakeText(context, "Received intent!", ToastLength.Short).Show();
}
}
}
并由AndroidManifest.xml
进行修改,看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.companyname.SMSIP2" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="25" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:label="SMSIP2.Android"></application>
</manifest>
现在,当我重新启动设备(或通过广播android.intent.action.BOOT_COMPLETED
消息触发接收器)时,我收到以下错误消息:
Java.Lang.RuntimeException: Unable to instantiate receiver md5b010e9266249275df36d0fbfd645bb11.BootReceiver:
java.lang.ClassNotFoundException: Didn't find class "md5b010e9266249275df36d0fbfd645bb11.BootReceiver" on path:
DexPathList[[zip file "/data/app/com.companyname.SMSIP2-1/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.SMSIP2-1/lib/x86_64, /data/app/com.companyname.SMSIP2-1/base.apk!/lib/x86_64, /system/lib64, /vendor/lib64]]
说实话,我并不真正理解为什么会出现这个错误,因为我遵循了典型的指令(例如these)。