0
無法讓我的Xamarin.Android應用在啓動後啓動Toast。我查了很多被接受的解決方案,但似乎沒有解決我的問題。我也嘗試了各種「工作」的例子,但沒有任何運氣,所以我錯過了一些東西。BroadcastReceiver在啓動後不會燒製
設備:三星Galaxy S3 API:19
Android清單
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.novak" 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="ReceiverApp">
<receiver android:enabled="true"
android:exported="true"
android-permission="android.permission.RECEIVE_BOOT_COMPLETED"
android:name="com.novak.BootReceiver" >
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>
BootReceiver.cs
using Android.App;
using Android.Widget;
using Android.Content;
namespace ReceiverApp
{
[BroadcastReceiver]
[IntentFilter(new[] { Intent.ActionBootCompleted })]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Toast.MakeText(context, "Receiver", ToastLength.Long).Show();
}
}
}
集[廣播接收器(啓用=真)]在BootReceiver類的屬性,看示例這裏:https://forums.xamarin.com/discussion/19448/example-for-broadcastreceiver-in-android – Alexandre
增加了[BroadcastReceiver(Enabled = true)]但仍然無法正常工作。有另一種方法來測試它是否正常工作嗎?也許我只是沒有看到吐司。 – Bob