您好我一直在尝试创建一个广播接收器,但我无法调用它,即从应用程序启动启动它在这里是我的代码请告诉我,是否缺少某些东西是我现在尝试的东西< / p>
<?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}
}
}
答案 0 :(得分:1)
这就是它在我的设备上的工作方式
[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
。