Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Android.Widget;
- using Android.App;
- using Android.OS;
- using Android.Views;
- using Android.Telephony;
- using Android.Content;
- using System;
- using Android.Support.V7.App;
- using Android.Runtime;
- using SVTTR;
- namespace SVTTR
- {
- [Activity(Label = "PhoneCall", Theme = "@style/AppTheme", MainLauncher = true)]
- public class MainActivity : Activity, View.IOnClickListener
- {
- EditText userNum;
- Button callBtn;
- string no = "";
- protected override void OnCreate(Bundle savedInstanceState)
- {
- base.OnCreate(savedInstanceState);
- // Set our view from the "main" layout resource
- SetContentView(Resource.Layout.activity_main);
- initialize();
- StateListener phoneStateListener = new StateListener(this);
- TelephonyManager telephonyManager = (TelephonyManager)GetSystemService(Context.TelephonyService);
- telephonyManager.Listen(phoneStateListener, PhoneStateListenerFlags.CallState);
- }
- //тут я пытаюсь завершить звонок
- public void UpdateCallState(CallState state, string incomingNumber)
- {
- if(state== CallState.Offhook)
- {
- Finish();
- }
- }
- public void initialize()
- {
- userNum = (EditText)FindViewById(Resource.Id.number);
- callBtn = (Button)FindViewById(Resource.Id.call);
- callBtn.SetOnClickListener(this);
- }
- public void OnClick(View v)
- {
- if (!userNum.Text.ToString().Equals(""))
- {
- no = userNum.Text.ToString();
- Intent callIntent = new Intent(Intent.ActionCall);
- callIntent.SetData(Android.Net.Uri.Parse("tel:" + no));
- callIntent.SetPackage("com.android.server.telecom");
- StartActivity(callIntent);
- }
- }
- //хочу получить статус звонка
- public class StateListener : PhoneStateListener
- {
- private readonly MainActivity _activity;
- public StateListener(MainActivity activity)
- {
- _activity = activity;
- }
- public override void OnCallStateChanged(CallState state, string incomingNumber)
- {
- base.OnCallStateChanged(state, incomingNumber);
- _activity.UpdateCallState(state, incomingNumber);
- }
- }
- }}
Add Comment
Please, Sign In to add comment