Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- // TODO Auto-generated method stub
- final Entity_BikeShopRepair toko = adapterShop.getItem(position);
- CharSequence[] items = { "View on Map", "Call Shop" };
- AlertDialog.Builder builder = new AlertDialog.Builder(
- Tab_Shop_Repair_ListView_Activity.this);
- builder.setTitle(toko.getShop_Name());
- builder.setItems(items, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int item) {
- switch (item) {
- case 0:
- Toast.makeText(Tab_Shop_Repair_ListView_Activity.this,
- toko.getShop_Name(), Toast.LENGTH_LONG).show();
- break;
- case 1:
- arrayList(Tab_Shop_Repair_ListView_Activity.this,
- toko.getPhone_Number());
- Intent intent = new Intent(Intent.ACTION_CALL, Uri
- .parse(arrayList.toString()));
- startActivity(intent);
- break;
- case 2:
- break;
- }
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
- }
- String number = "tel:" + toko.getPhone_Number().toString();
- Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number));
- startActivity(callIntent);
- <uses-permission android:name="android.permission.CALL_PHONE" />
- <uses-permission android:name="android.permission.CALL_PHONE" />
- Intent callIntent = new Intent(Intent.ACTION_VIEW);
- callIntent.setData(Uri.parse("tel:" + ph_no));
- startActivity(callIntent);
- PhoneCallListener phoneListener = new PhoneCallListener();
- TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
- telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
- private class PhoneCallListener extends PhoneStateListener {
- private boolean isPhoneCalling = false;
- String LOG_TAG = "LOGGING 123";
- @Override
- public void onCallStateChanged(int state, String incomingNumber) {
- if (TelephonyManager.CALL_STATE_RINGING == state) {
- // phone ringing
- Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
- }
- if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
- // active
- Log.i(LOG_TAG, "OFFHOOK");
- isPhoneCalling = true;
- }
- if (TelephonyManager.CALL_STATE_IDLE == state) {
- // run when class initial and phone call ended,
- // need detect flag from CALL_STATE_OFFHOOK
- Log.i(LOG_TAG, "IDLE");
- if (isPhoneCalling) {
- Log.i(LOG_TAG, "restart app");
- // restart app
- Intent i = getBaseContext().getPackageManager()
- .getLaunchIntentForPackage(
- getBaseContext().getPackageName());
- i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(i);
- isPhoneCalling = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement