Ich versuche, eine Benachrichtigung anzuzeigen, wenn ein ausgehender Anruf getätigt wird, aber es funktioniert nicht (nichts wird angezeigt). Ich habe die Benachrichtigung separat getestet, es funktioniert gut, aber ich bin mir ziemlich sicher, dass ich im BroadcastReceiver etwas falsch gemacht habe. Vielen Dank im Voraus!Xamarin/Android App: Broadcast-Empfänger funktioniert nicht
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 Klasse:
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);
}
}
}
Haben Sie Berechtigungen hinzufügen abgehende Anrufe zu verarbeiten? ('PROCESS_OUTGOING_CALLS') – SushiHangover