発信コールが行われたときに通知を表示しようとしていますが、動作しません(何も表示されません)。私は別に通知をテストしましたが、うまくいきましたが、私はBroadcastReceiverで何か問題があったと確信しています。 ありがとうございます!Xamarin/Androidアプリ:放送受信機が動作しない
MainActivity:
[Activity(Label = "ExamProject", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
MyBroadcastRecieverClass reciever;
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
reciever = new MyBroadcastRecieverClass();
RegisterReceiver(reciever, new IntentFilter("android.intent.action.NEW_OUTGOING_CALL"));
BroadcastRecieverクラス:
namespace App3
{
[BroadcastReceiver(Enabled = true, Exported = true)]
[IntentFilter(new[] { Android.Content.Intent.ActionNewOutgoingCall })]
public class MyBroadcastRecieverClass: BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
// Do stuff here.
//String value = intent.GetStringExtra("key");
Notification.Builder builder = new Notification.Builder(Application.Context)
.SetContentTitle("Test Title")
.SetContentText("test content")
.SetSmallIcon(Resource.Drawable.Icon)
.SetPriority(100)
.SetDefaults(NotificationDefaults.Sound)
.SetVisibility(NotificationVisibility.Public)
.SetCategory(Notification.CategoryAlarm);
//build the notification
Notification test = builder.Build();
// Get the notification manager:
NotificationManager notificationManager =
context.GetSystemService(Context.NotificationService) as NotificationManager;
// Publish the notification:
const int notificationId = 0;//should be changed to generate a uniqe value
notificationManager.Notify(notificationId, test);
}
}
}
あなたは、発信電話を処理する権限を追加しましたか? ( 'PROCESS_OUTGOING_CALLS') – SushiHangover