daily pastebin goal
37%
SHARE
TWEET

Untitled

a guest Feb 19th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Override
  2. protected void onListItemClick(ListView l, View v, int position, long id) {
  3.     // TODO Auto-generated method stub
  4.     final Entity_BikeShopRepair toko = adapterShop.getItem(position);
  5.  
  6.     CharSequence[] items = { "View on Map", "Call Shop" };
  7.  
  8.     AlertDialog.Builder builder = new AlertDialog.Builder(
  9.             Tab_Shop_Repair_ListView_Activity.this);
  10.     builder.setTitle(toko.getShop_Name());
  11.     builder.setItems(items, new DialogInterface.OnClickListener() {
  12.         public void onClick(DialogInterface dialog, int item) {
  13.             switch (item) {
  14.             case 0:
  15.                 Toast.makeText(Tab_Shop_Repair_ListView_Activity.this,
  16.                         toko.getShop_Name(), Toast.LENGTH_LONG).show();
  17.                 break;
  18.             case 1:
  19.                 arrayList(Tab_Shop_Repair_ListView_Activity.this,
  20.                         toko.getPhone_Number());
  21.                 Intent intent = new Intent(Intent.ACTION_CALL, Uri
  22.                         .parse(arrayList.toString()));
  23.                 startActivity(intent);
  24.  
  25.                 break;
  26.             case 2:
  27.                 break;
  28.             }
  29.         }
  30.     });
  31.     AlertDialog alert = builder.create();
  32.     alert.show();
  33. }
  34.    
  35. String number = "tel:" + toko.getPhone_Number().toString();
  36.     Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
  37.     startActivity(callIntent);
  38.    
  39. <uses-permission android:name="android.permission.CALL_PHONE" />
  40.    
  41. <uses-permission android:name="android.permission.CALL_PHONE" />
  42.    
  43. Intent callIntent = new Intent(Intent.ACTION_VIEW);
  44. callIntent.setData(Uri.parse("tel:" + ph_no));
  45. startActivity(callIntent);
  46.    
  47. PhoneCallListener phoneListener = new PhoneCallListener();
  48. TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
  49. telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
  50.    
  51. private class PhoneCallListener extends PhoneStateListener {
  52.  
  53.     private boolean isPhoneCalling = false;
  54.  
  55.     String LOG_TAG = "LOGGING 123";
  56.  
  57.     @Override
  58.     public void onCallStateChanged(int state, String incomingNumber) {
  59.  
  60.         if (TelephonyManager.CALL_STATE_RINGING == state) {
  61.             // phone ringing
  62.             Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
  63.         }
  64.  
  65.         if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
  66.             // active
  67.             Log.i(LOG_TAG, "OFFHOOK");
  68.  
  69.             isPhoneCalling = true;
  70.         }
  71.  
  72.         if (TelephonyManager.CALL_STATE_IDLE == state) {
  73.             // run when class initial and phone call ended,
  74.             // need detect flag from CALL_STATE_OFFHOOK
  75.             Log.i(LOG_TAG, "IDLE");
  76.  
  77.             if (isPhoneCalling) {
  78.  
  79.                 Log.i(LOG_TAG, "restart app");
  80.  
  81.                 // restart app
  82.                 Intent i = getBaseContext().getPackageManager()
  83.                         .getLaunchIntentForPackage(
  84.                                 getBaseContext().getPackageName());
  85.                 i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  86.                 startActivity(i);
  87.  
  88.                 isPhoneCalling = false;
  89.             }
  90.  
  91.         }
  92.     }
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top