我试图覆盖默认的外拨拨号程序,并将其替换为我的活动。我已经让我的接收器工作并在拨打电话时正确响应,但我无法弄清楚如何阻止默认拨号器显示并将其替换为我的自定义布局。
当我切换回自定义应用程序时,我可以看到它已加载我的拨号程序布局。它不代替默认拨号器或显示在默认拨号器的顶部。有什么想法吗?
主要活动:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace minuteSaver
{
[Activity (Label = "minuteSaver", MainLauncher = true)]
public class MainActivity : Activity
{
private icCall _receiver;
int count = 1;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
#region Code for using delegate to access class
var filter = new IntentFilter();
filter.AddAction(Intent.ActionNewOutgoingCall);
var receiver = new icCall { OnReceiveAction = () => {
Toast notifyUser = Toast.MakeText(this, "test", ToastLength.Long);
if (filter.GetAction(0) == Intent.ActionNewOutgoingCall)
{
notifyUser.Show();
var second = new Intent(this, typeof(mdCall));
second.AddFlags(ActivityFlags.ClearTop);
second.AddFlags(ActivityFlags.NewTask);
StartActivity(second);
}
}};
RegisterReceiver(receiver, filter);
#endregion
Console.WriteLine ("Receiver registered.");
}
}
}
BroadcastReceiver类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Telephony;
namespace minuteSaver
{
[BroadcastReceiver (Enabled = true, Exported = false)]
[IntentFilter(new string[] { "android.intent.action.NEW_OUTGOING_CALL" }, Priority = (int)IntentFilterPriority.HighPriority)]
class icCall:BroadcastReceiver
{
public Action OnReceiveAction;
public override void OnReceive (Context context, Intent intent)
{
if (OnReceiveAction != null)
{
OnReceiveAction.Invoke ();
InvokeAbortBroadcast ();
}
Toast notifyUser = Toast.MakeText(context, "test", ToastLength.Short);
if (intent.Action == Intent.ActionNewOutgoingCall)
{
InvokeAbortBroadcast ();
Wait (900);
Intent i = new Intent (context, typeof(mdCall));
i.AddFlags(ActivityFlags.ClearTop);
i.AddFlags(ActivityFlags.NewTask);
context.StartActivity (i);
notifyUser.Show();
Console.WriteLine ("Debug: Outgoing call detected");
}
}
}
}