无法在应用程序启动时调用广播接收器
Unable to call broadcast receiver on App startup
你好,我一直在尝试创建一个广播接收器,但我无法调用它,即从应用程序启动启动它这是我的代码请告诉我是否缺少某些东西这是我尝试过的东西现在
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.testing.broacast" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:label="App4"></application>
<receiver android:name=".Broadcast">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</manifest>
这是我的广播接收器
[BroadcastReceiver]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class Broadcast : BroadcastReceiver
{
public override void OnReceive(Context context,Intent intent)
{
Toast.MakeText(context, "Hello", ToastLength.Long).Show();
// Create your application here}
}
}
这是它在我的设备上的工作方式
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class Broadcast : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Toast.MakeText(context, "Hello", ToastLength.Long).Show();
}
}
区别是[BroadcastReceiver(Enabled = true)]
此外,我不需要将 receiver
标签放入我的 AndroidManifest.xml
。
你好,我一直在尝试创建一个广播接收器,但我无法调用它,即从应用程序启动启动它这是我的代码请告诉我是否缺少某些东西这是我尝试过的东西现在
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.testing.broacast" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:label="App4"></application>
<receiver android:name=".Broadcast">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</manifest>
这是我的广播接收器
[BroadcastReceiver]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class Broadcast : BroadcastReceiver
{
public override void OnReceive(Context context,Intent intent)
{
Toast.MakeText(context, "Hello", ToastLength.Long).Show();
// Create your application here}
}
}
这是它在我的设备上的工作方式
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class Broadcast : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Toast.MakeText(context, "Hello", ToastLength.Long).Show();
}
}
区别是[BroadcastReceiver(Enabled = true)]
此外,我不需要将 receiver
标签放入我的 AndroidManifest.xml
。