Guest User

Untitled

a guest
Feb 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. using Android.Widget;
  2. using Android.App;
  3. using Android.OS;
  4. using Android.Views;
  5. using Android.Telephony;
  6. using Android.Content;
  7. using System;
  8. using Android.Support.V7.App;
  9. using Android.Runtime;
  10. using SVTTR;
  11.  
  12. namespace SVTTR
  13. {
  14. [Activity(Label = "PhoneCall", Theme = "@style/AppTheme", MainLauncher = true)]
  15. public class MainActivity : Activity, View.IOnClickListener
  16. {
  17. EditText userNum;
  18. Button callBtn;
  19. string no = "";
  20.  
  21. protected override void OnCreate(Bundle savedInstanceState)
  22. {
  23. base.OnCreate(savedInstanceState);
  24. // Set our view from the "main" layout resource
  25. SetContentView(Resource.Layout.activity_main);
  26. initialize();
  27.  
  28.  
  29. StateListener phoneStateListener = new StateListener(this);
  30. TelephonyManager telephonyManager = (TelephonyManager)GetSystemService(Context.TelephonyService);
  31. telephonyManager.Listen(phoneStateListener, PhoneStateListenerFlags.CallState);
  32. }
  33. //тут я пытаюсь завершить звонок
  34. public void UpdateCallState(CallState state, string incomingNumber)
  35. {
  36. if(state== CallState.Offhook)
  37. {
  38. Finish();
  39. }
  40. }
  41.  
  42.  
  43. public void initialize()
  44. {
  45. userNum = (EditText)FindViewById(Resource.Id.number);
  46. callBtn = (Button)FindViewById(Resource.Id.call);
  47. callBtn.SetOnClickListener(this);
  48. }
  49.  
  50.  
  51.  
  52. public void OnClick(View v)
  53. {
  54. if (!userNum.Text.ToString().Equals(""))
  55. {
  56. no = userNum.Text.ToString();
  57. Intent callIntent = new Intent(Intent.ActionCall);
  58. callIntent.SetData(Android.Net.Uri.Parse("tel:" + no));
  59.  
  60. callIntent.SetPackage("com.android.server.telecom");
  61. StartActivity(callIntent);
  62.  
  63. }
  64. }
  65. //хочу получить статус звонка
  66. public class StateListener : PhoneStateListener
  67. {
  68. private readonly MainActivity _activity;
  69.  
  70. public StateListener(MainActivity activity)
  71. {
  72. _activity = activity;
  73. }
  74.  
  75.  
  76. public override void OnCallStateChanged(CallState state, string incomingNumber)
  77. {
  78.  
  79. base.OnCallStateChanged(state, incomingNumber);
  80. _activity.UpdateCallState(state, incomingNumber);
  81. }
  82. }
  83. }}
Add Comment
Please, Sign In to add comment