Last active
September 23, 2015 11:36
-
-
Save Cheesebaron/a856fde77833f0c267e1 to your computer and use it in GitHub Desktop.
Handle call and dial intents
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<TextView | |
android:text="Calling" | |
android:textAppearance="?android:attr/textAppearanceLarge" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" /> | |
<TextView | |
android:text="0000-0000-0000" | |
android:textAppearance="?android:attr/textAppearanceMedium" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/textView1" | |
android:layout_gravity="center" /> | |
<ImageView | |
android:src="@android:drawable/sym_action_call" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:id="@+id/imageView1" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.App; | |
using Android.Content; | |
using Android.Content.PM; | |
using Android.OS; | |
using Android.Widget; | |
namespace Your.Namespace | |
{ | |
[Activity(Label = "Call", LaunchMode = LaunchMode.SingleTop)] | |
[IntentFilter(new[] { Intent.ActionCall, Intent.ActionView }, | |
Categories = new[] { Intent.CategoryDefault }, | |
DataScheme = "tel")] | |
public class CallActivity : Activity | |
{ | |
private TextView _numberTextView; | |
protected override void OnCreate(Bundle savedInstanceState) | |
{ | |
base.OnCreate(savedInstanceState); | |
SetContentView(Resource.Layout.call); | |
_numberTextView = FindViewById<TextView>(Resource.Id.textView1); | |
var numberUri = Intent.Data; | |
_numberTextView.Text = numberUri.SchemeSpecificPart; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.App; | |
using Android.Content; | |
using Android.Content.PM; | |
using Android.OS; | |
using Android.Widget; | |
namespace Your.Namespace | |
{ | |
[Activity(Label = "Dial", LaunchMode = LaunchMode.SingleTop)] | |
[IntentFilter(new[] { Intent.ActionDial, Intent.ActionCallButton, Intent.ActionView }, | |
Categories = new[] { Intent.CategoryDefault }, | |
DataScheme = "tel")] | |
public class DialActivity : Activity | |
{ | |
private TextView _numberTextView; | |
protected override void OnCreate(Bundle savedInstanceState) | |
{ | |
base.OnCreate(savedInstanceState); | |
SetContentView(Resource.Layout.telephone); | |
_numberTextView = FindViewById<TextView>(Resource.Id.textView1); | |
var numberUri = Intent.Data; | |
_numberTextView.Text = numberUri.SchemeSpecificPart; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<Button | |
android:text="Dial" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:id="@+id/buttondial" /> | |
<Button | |
android:text="Call" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:id="@+id/buttoncall" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.App; | |
using Android.Content; | |
using Android.Net; | |
using Android.OS; | |
using Android.Widget; | |
namespace Your.Namespace | |
{ | |
[Activity(Label = "Call/Dial Test", MainLauncher = true, Icon = "@drawable/icon")] | |
public class MainActivity : Activity | |
{ | |
protected override void OnCreate(Bundle bundle) | |
{ | |
base.OnCreate(bundle); | |
// Set our view from the "main" layout resource | |
SetContentView(Resource.Layout.main); | |
var call = FindViewById<Button>(Resource.Id.buttoncall); | |
var dial = FindViewById<Button>(Resource.Id.buttondial); | |
call.Click += (sender, args) => | |
{ | |
var number = Uri.Parse("tel:12345678"); | |
var intent = new Intent(Intent.ActionCall, number); | |
StartActivity(intent); | |
}; | |
dial.Click += (sender, args) => | |
{ | |
var number = Uri.Parse("tel:12345678"); | |
var intent = new Intent(Intent.ActionDial, number); | |
StartActivity(intent); | |
}; | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android; | |
using Android.App; | |
using Android.Content; | |
using Android.Net; | |
[assembly: Permission(Name = Manifest.Permission.ProcessOutgoingCalls)] | |
namespace Your.Namespace | |
{ | |
[BroadcastReceiver(Enabled = true)] | |
[IntentFilter(new[] { Intent.ActionNewOutgoingCall }, | |
Categories = new[] { Intent.CategoryDefault })] | |
public class OutgoingCallReceiver : BroadcastReceiver | |
{ | |
public override void OnReceive(Context context, Intent intent) | |
{ | |
var phoneNumber = ResultData ?? intent.GetStringExtra(Intent.ExtraPhoneNumber); | |
// my app will handle the data | |
ResultData = null; | |
// start my app | |
var myCallerIntent = new Intent(context, typeof (CallActivity)); | |
myCallerIntent.SetData(Uri.Parse("tel:" + phoneNumber)); | |
myCallerIntent.SetFlags(ActivityFlags.NewTask); | |
context.StartActivity(myCallerIntent); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:orientation="vertical" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:padding="10dp"> | |
<LinearLayout | |
android:orientation="horizontal" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="20dp"> | |
<TextView | |
android:textAppearance="?android:attr/textAppearanceLarge" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/textView1" | |
android:singleLine="true" | |
android:inputType="phone" | |
android:hint="number" /> | |
<Button | |
android:text="Del" | |
android:layout_width="60dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/buttondel" /> | |
</LinearLayout> | |
<LinearLayout | |
android:orientation="horizontal" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<Button | |
android:text="1" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/button1" /> | |
<Button | |
android:text="2" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/button2" /> | |
<Button | |
android:text="3" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/button3" /> | |
</LinearLayout> | |
<LinearLayout | |
android:orientation="horizontal" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<Button | |
android:text="4" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/button4" /> | |
<Button | |
android:text="5" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/button5" /> | |
<Button | |
android:text="6" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/button6" /> | |
</LinearLayout> | |
<LinearLayout | |
android:orientation="horizontal" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<Button | |
android:text="7" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/button7" /> | |
<Button | |
android:text="8" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/button8" /> | |
<Button | |
android:text="9" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/button9" /> | |
</LinearLayout> | |
<LinearLayout | |
android:orientation="horizontal" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<Button | |
android:text="#" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/buttonhash" /> | |
<Button | |
android:text="0" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/button0" /> | |
<Button | |
android:text="+" | |
android:layout_weight="1" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:id="@+id/buttonplus" /> | |
</LinearLayout> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dear Cheesebaron,
At first i want to honestly thank you for your support in general.
The above example is pretty easy and straight forward.
When the CallActivity is started is smoothly overlap the default dialer screen.
My issue is that i cant hear the dial tone, because basically is just showing a new dial screen and not actually make a call to a number.
Thanks in advance.