Guest User

Untitled

a guest
Mar 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. myBtn.setOnClickListener(new View.OnClickListener() {
  2.  
  3. @Override
  4. public void onClick(View v) {
  5.  
  6. if(ContextCompat.checkSelfPermission(MainActivity.this,
  7. Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)
  8. {} else {
  9. requestReadPhonePermission();
  10. }
  11. };// move the things you do with the telephony in the callback;
  12. }
  13.  
  14. @Override
  15. public void onRequestPermissionsResult(int requestCode,
  16. String permissions[], int[] grantResults) {
  17. switch (requestCode) {
  18. case Phone_State_Permission_Code: {
  19.  
  20. // If request is cancelled, the result arrays are empty.
  21. if (grantResults.length > 0
  22. && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  23.  
  24. // permission was granted, yay! Do the
  25. // contacts-related task you need to do.
  26. TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
  27.  
  28. String IMEInum;
  29. IMEInum=tm.getDeviceId();
  30. IMEI.setText("IMEI: "+IMEInum);
  31.  
  32.  
  33. String lineNum = tm.getLine1Number();
  34. Linenum.setText("Line number: "+lineNum);
  35.  
  36. int phoneType=tm.getPhoneType();
  37. switch (phoneType)
  38. {
  39. case (TelephonyManager.PHONE_TYPE_CDMA):
  40. Phonetype.setText("Phone type: CDMA");
  41. break;
  42. case (TelephonyManager.PHONE_TYPE_GSM):
  43. Phonetype.setText("Phone type: GSM");
  44. break;
  45. case (TelephonyManager.PHONE_TYPE_NONE):
  46. Phonetype.setText("Phone type: NONE");
  47. break;
  48. }
  49.  
  50. int CallState = tm.getCallState();
  51. switch (CallState) {
  52. case TelephonyManager.CALL_STATE_IDLE:
  53. Call.setText("CALL STATE : IDLE");
  54. break;
  55. case TelephonyManager.CALL_STATE_OFFHOOK:
  56. Call.setText("CALL STATE : OFFHOOK");
  57. break;
  58. case TelephonyManager.CALL_STATE_RINGING:
  59. Call.setText("CALL STATE : RINGING");
  60. break;
  61. }
  62.  
  63. int SIMState=tm.getSimState();
  64. switch(SIMState)
  65. {
  66. case TelephonyManager.SIM_STATE_ABSENT :
  67. Sim.setText("SIM state: ABSENT");
  68. break;
  69. case TelephonyManager.SIM_STATE_NETWORK_LOCKED :
  70. Sim.setText("SIM state: NETWORK LOCKED");
  71. break;
  72. case TelephonyManager.SIM_STATE_PIN_REQUIRED :
  73. Sim.setText("SIM state: PIN REQUIRED");
  74. break;
  75. case TelephonyManager.SIM_STATE_PUK_REQUIRED :
  76. Sim.setText("SIM state: PUK REQUIRED");
  77. break;
  78. case TelephonyManager.SIM_STATE_READY :
  79. Sim.setText("SIM state: READY");
  80. break;
  81. case TelephonyManager.SIM_STATE_UNKNOWN :
  82. Sim.setText("SIM state: UNKNOWN");
  83. break;
  84.  
  85. }
  86.  
  87. } else {
  88.  
  89. // permission denied, boo! Disable the
  90. // functionality that depends on this permission.
  91. //handle the situation if the permission was denied;
  92. }
  93. return;
  94. }
  95.  
  96. // other 'case' lines to check for other
  97. // permissions this app might request
  98. }
  99. }
Add Comment
Please, Sign In to add comment