Example usage for android.content Intent ACTION_CALL

List of usage examples for android.content Intent ACTION_CALL

Introduction

In this page you can find the example usage for android.content Intent ACTION_CALL.

Prototype

String ACTION_CALL

To view the source code for android.content Intent ACTION_CALL.

Click Source Link

Document

Activity Action: Perform a call to someone specified by the data.

Usage

From source file:com.hch.beautyenjoy.tools.IntentUtils.java

/**
 * Call up, requires Permission "android.permission.CALL_PHONE"
 *///from ww  w .  ja v  a  2s.  c om
public static void call(Context context, String number) {
    Uri uri = Uri.parse("tel:" + number);
    Intent intent = new Intent(Intent.ACTION_CALL, uri);
    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        return;
    }
    //        context.startActivity(intent);
}

From source file:com.photobox.android.iris.MyFirebaseMessagingService.java

private void makeCall(String number) {
    final Intent dial = new Intent(Intent.ACTION_CALL);
    dial.setData(Uri.parse("tel:" + Uri.encode(number)));
    //this.getApplicationContext().startActivity(dial);
}

From source file:net.openwatch.acluaz.RightsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    case R.id.menu_call:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getString(R.string.call_aclu_dialog_title))
                .setPositiveButton(getString(R.string.call_aclu_dialog_call), new OnClickListener() {

                    @Override/*  w w w. j av a  2s. c om*/
                    public void onClick(DialogInterface dialog, int which) {
                        String url = "tel:18552258291";
                        Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
                        startActivity(intent);
                    }
                }).setNegativeButton(getString(R.string.dialog_cancel), new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();

        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:pedromendes.tempodeespera.HospitalDetailActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hospital_detail);

    Typeface font = Typeface.createFromAsset(getAssets(), "fontawesome-webfont.ttf");

    Long hospitalId = getIntent().getExtras().getLong("HOSPITAL_ID");
    String hospitalName = getIntent().getExtras().getString("HOSPITAL_NAME");
    String hospitalDescription = getIntent().getExtras().getString("HOSPITAL_DESCRIPTION");
    String hospitalAddress = getIntent().getExtras().getString("HOSPITAL_ADDRESS");
    final String hospitalPhone = getIntent().getExtras().getString("HOSPITAL_PHONE");
    String hospitalEmail = getIntent().getExtras().getString("HOSPITAL_EMAIL");
    String latitude = getIntent().getExtras().getString("HOSPITAL_LAT");
    String longitude = getIntent().getExtras().getString("HOSPITAL_LONG");

    TextView hospitalNameView = (TextView) findViewById(R.id.hospitalName);
    hospitalNameView.setText(hospitalName);

    if (hospitalAddress != null && !hospitalAddress.isEmpty()) {
        TextView hospitalAddressView = (TextView) findViewById(R.id.hospitalAddress);
        hospitalAddressView.setText(Html.fromHtml(hospitalAddress + "<br/>" + "<a href=\"geo:" + latitude + ","
                + longitude + "\">" + "Ver mapa" + "</a>"));
        hospitalAddressView.setMovementMethod(LinkMovementMethod.getInstance());
    }//from ww w  .ja v  a 2 s. c  o  m

    if (hospitalPhone != null && !hospitalPhone.isEmpty()) {
        Button hospitalPhoneView = (Button) findViewById(R.id.hospitalPhone);
        hospitalPhoneView.append(" " + hospitalPhone);
        hospitalPhoneView.setTypeface(font);

        hospitalPhoneView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:" + hospitalPhone));
                callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                if (ActivityCompat.checkSelfPermission(getApplicationContext(),
                        Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                    return;
                }
                startActivity(callIntent);
            }
        });
    }

    dialog = new ProgressDialog(this);
    dialog.setMessage("A carregar...");
    dialog.show();

    new RequestHospitalDetailTask().execute(hospitalId.toString());
}

From source file:com.hut.cwp.mcar.activitys.business.MoveCarActivity.java

public void init() {
    mTvPhone = (TextView) findViewById(R.id.tv_move_car_phone);
    mTvHint = (TextView) findViewById(R.id.tv_move_car_hint);
    mBtCall = (Button) findViewById(R.id.bt_move_car_call);
    mFlLoading = (FrameLayout) findViewById(R.id.rl_move_car_loading);
    mTvPhone.setOnClickListener(new View.OnClickListener() {
        @Override/*from  www .  j  a v a2  s .  c  om*/
        public void onClick(View v) {
            //
            LsnumDialog dialog = new LsnumDialog(MoveCarActivity.this);
            dialog.setCompletedListener(new LsnumDialog.ICompleted() {
                @Override
                public void afterCompleted(final String result) {
                    mTvPhone.setText(result);
                    mFlLoading.setVisibility(View.VISIBLE);
                    new Thread(() -> {
                        BmobQuery<CarInfo> query = new BmobQuery<>();
                        query.addWhereEqualTo("licensePlate", result);
                        query.setLimit(1);
                        query.findObjects(new FindListener<CarInfo>() {
                            @Override
                            public void done(final List<CarInfo> object, final BmobException e) {
                                mHandler.post(() -> {
                                    if (e == null && object.size() != 0) {
                                        phone = object.get(0).getUsername();
                                    } else {
                                        if (e != null)
                                            Log.i("bmob",
                                                    "" + e.getMessage() + "," + e.getErrorCode());
                                        mBtCall.setBackgroundResource(R.drawable.z_bcg_move_car_failed);
                                        phone = null;
                                        mTvHint.setText("?");
                                    }
                                    mFlLoading.setVisibility(View.GONE);
                                });
                            }
                        });
                    }).start();
                }
            });
            try {
                mTvHint.setText("?");
                phone = null;
                mTvPhone.setText("");
                mBtCall.setBackgroundResource(R.drawable.z_bcg_feedback_success);
                dialog.show(getSupportFragmentManager());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    mBtCall.setOnClickListener(v -> {
        if (!TextUtils.isEmpty(phone)) {
            Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone));
            if (ActivityCompat.checkSelfPermission(MoveCarActivity.this,
                    Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            startActivity(intent);
        } else {
            Toast.makeText(MoveCarActivity.this, "?", Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:edu.cwru.apo.Directory.java

public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btnCall:
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:" + lastPhone));
        startActivity(intent);//from  w  ww.  j a  v a2s . c o m
        break;

    case R.id.btnText:
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", lastPhone, null)));
        break;

    default:
        String text = ((TextView) v).getText().toString();
        int start = text.lastIndexOf('[');
        int end = text.lastIndexOf(']');
        String caseID = text.substring(start + 1, end);
        Cursor results = database.query("phoneDB", new String[] { "first", "last", "_id", "phone" }, "_id = ?",
                new String[] { caseID }, null, null, null);
        if (results.getCount() != 1) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Error Loading Phone Number").setCancelable(false).setNeutralButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
        } else {
            results.moveToFirst();

            phoneDialog = new Dialog(this);
            phoneDialog.setContentView(R.layout.phone_dialog);
            phoneDialog.setTitle(results.getString(0) + " " + results.getString(1));

            TextView phoneText = (TextView) phoneDialog.findViewById((R.id.phoneText));
            String phoneNumber = removeNonDigits(results.getString(3));
            if (phoneNumber == null || phoneNumber.trim().equals("") || phoneNumber.trim().equals("null")) {
                ((Button) phoneDialog.findViewById(R.id.btnCall)).setEnabled(false);
                ((Button) phoneDialog.findViewById(R.id.btnText)).setEnabled(false);
                phoneNumber = "not available";
            } else {
                ((Button) phoneDialog.findViewById(R.id.btnCall)).setEnabled(true);
                ((Button) phoneDialog.findViewById(R.id.btnText)).setEnabled(true);
                ((Button) phoneDialog.findViewById(R.id.btnCall)).setOnClickListener(this);
                ((Button) phoneDialog.findViewById(R.id.btnText)).setOnClickListener(this);
            }
            lastPhone = phoneNumber;
            phoneText.setText("Phone Number: " + lastPhone);
            phoneDialog.show();
        }
        break;
    }
}

From source file:com.anthonykeane.speedzone.ActivityRecognitionIntentService.java

/**
 * Called when a new activity detection update is available.
 *//*from  w  w w . ja va  2s  .co m*/
@Override
protected void onHandleIntent(Intent intent) {

    // Get a handle to the repository
    mPrefs = getApplicationContext().getSharedPreferences(ActivityUtils.SHARED_PREFERENCES,
            Context.MODE_PRIVATE);

    // Get a date formatter, and catch errors in the returned timestamp
    try {
        mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance();
    } catch (Exception e) {
        Log.e(ActivityUtils.APPTAG, getString(R.string.date_format_error));
    }

    // Format the timestamp according to the pattern, then localize the pattern
    mDateFormat.applyPattern(DATE_FORMAT_PATTERN);
    mDateFormat.applyLocalizedPattern(mDateFormat.toLocalizedPattern());

    // If the intent contains an update
    if (ActivityRecognitionResult.hasResult(intent)) {

        // Get the update
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

        // Log the update
        logActivityRecognitionResult(result);

        // Get the most probable activity from the list of activities in the update
        DetectedActivity mostProbableActivity = result.getMostProbableActivity();

        // Get the confidence percentage for the most probable activity
        int confidence = mostProbableActivity.getConfidence();

        // Get the type of activity
        int activityType = mostProbableActivity.getType();

        // Check to see if the repository contains a previous activity
        if (!mPrefs.contains(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE)) {

            // This is the first type an activity has been detected. Store the type
            SharedPreferences.Editor editor = mPrefs.edit();
            editor.putInt(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE, activityType);
            editor.commit();

            // If the repository contains a type
        } else if (activityChanged(activityType) // The activity has changed from the previous activity
                && (confidence >= 80)) // The confidence level for the current activity is > 50%
        {

            switch (activityType) {
            case DetectedActivity.IN_VEHICLE:
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                callIntent.setClass(getApplicationContext(), MainActivity.class);
                // todo   callIntent.putExtra("bZoneError",bZoneError);
                startActivity(callIntent);
                break;
            //case DetectedActivity.STILL:
            //case DetectedActivity.ON_BICYCLE:
            case DetectedActivity.ON_FOOT:
                //sendNotification();
                break;

            }

        }
    }
}

From source file:com.sonetel.plugins.sonetelcallthru.CallThru.java

@Override
public void onReceive(final Context context, Intent intent) {
    if (SipManager.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {
        // Retrieve and cache infos from the phone app 
        if (!sPhoneAppInfoLoaded) {
            Resources r = context.getResources();
            BitmapDrawable drawable = (BitmapDrawable) r.getDrawable(R.drawable.ic_wizard_sonetel);
            sPhoneAppBmp = drawable.getBitmap();

            sPhoneAppInfoLoaded = true;//from w  w w. ja  v  a2 s  .  c  o m
        }

        Bundle results = getResultExtras(true);
        //if(pendingIntent != null) {
        //   results.putParcelable(CallHandlerPlugin.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        //}
        results.putString(Intent.EXTRA_TITLE, "Call thru");// context.getResources().getString(R.string.use_pstn));
        if (sPhoneAppBmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, sPhoneAppBmp);
        }
        if (intent.getStringExtra(Intent.EXTRA_TEXT) == null)
            return;

        //final PendingIntent pendingIntent = null;
        final String callthrunum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        final String dialledNum = intent.getStringExtra(Intent.EXTRA_TEXT);
        // We must handle that clean way cause when call just to 
        // get the row in account list expect this to reply correctly
        if (callthrunum != null && PhoneCapabilityTester.isPhone(context)) {

            if (!callthrunum.equalsIgnoreCase("")) {
                DBAdapter dbAdapt = new DBAdapter(context);

                // Build pending intent

                SipAccount = dbAdapt.getAccount(1);

                if (SipAccount != null) {

                    Intent i = new Intent(Intent.ACTION_CALL);
                    i.setData(Uri.fromParts("tel", callthrunum, null));
                    final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i,
                            PendingIntent.FLAG_CANCEL_CURRENT);

                    NetWorkThread = new Thread() {
                        public void run() {
                            SendMsgToNetWork(dialledNum, context, pendingIntent);
                        };
                    };

                    NetWorkThread.start();

                }

                if (!dialledNum.equalsIgnoreCase("")) {
                    SipCallSessionImpl callInfo = new SipCallSessionImpl();

                    callInfo.setRemoteContact(dialledNum);
                    callInfo.setIncoming(false);
                    callInfo.callStart = System.currentTimeMillis();
                    callInfo.setAccId(3);
                    //callInfo.setLastStatusCode(pjsua.PJ_SUCCESS);

                    ContentValues cv = CallLogHelper.logValuesForCall(context, callInfo, callInfo.callStart);
                    context.getContentResolver().insert(SipManager.CALLLOG_URI, cv);

                }
            } else {
                Location_Finder LocFinder = new Location_Finder(context);
                if (LocFinder.getContryName().startsWith("your"))
                    Toast.makeText(context,
                            "Country of your current location unknown. Call thru not available.",
                            Toast.LENGTH_LONG).show();
                else
                    Toast.makeText(context,
                            "No Call thru access number available in " + LocFinder.getContryName(),
                            Toast.LENGTH_LONG).show();
                //Toast.makeText(context, "No Call thru access number available in ", Toast.LENGTH_LONG).show();
            }
        }

        // This will exclude next time tel:xxx is raised from csipsimple treatment which is wanted
        results.putString(Intent.EXTRA_PHONE_NUMBER, callthrunum);

    }

}

From source file:com.wordpress.jftreading.FragmentMain.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.update_contact:
        startActivityForResult(new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI),
                PICK_CONTACT_REQUEST);/* w  ww. jav  a 2  s. c o m*/
        break;
    case R.id.call_btn:
        // Dial mobile number
        if (contactUri != null) {
            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:" + getMobileNumber(contactUri)));
            startActivity(callIntent);
        }
        break;
    case R.id.send_btn:
        String stextMessage = textMessage.getText().toString();
        if (stextMessage.matches("")) {

        } else if (contactUri != null) {

            dialog = ProgressDialog.show(getActivity(), "Sending", "Sending text message");
            Thread th = new Thread(new Runnable() {

                @Override
                public void run() {
                    // Send text message
                    try {
                        String SENT = "sent";
                        String DELIVERED = "delivered";

                        Intent sentIntent = new Intent(SENT);
                        //Create Pending Intents
                        PendingIntent sentPI = PendingIntent.getBroadcast(getActivity().getApplicationContext(),
                                0, sentIntent, PendingIntent.FLAG_UPDATE_CURRENT);

                        Intent deliveryIntent = new Intent(DELIVERED);

                        PendingIntent deliverPI = PendingIntent.getBroadcast(
                                getActivity().getApplicationContext(), 0, deliveryIntent,
                                PendingIntent.FLAG_UPDATE_CURRENT);
                        //Register for SMS send action
                        getActivity().registerReceiver(new BroadcastReceiver() {
                            String result = "";

                            @Override
                            public void onReceive(Context context, Intent intent) {

                                switch (getResultCode()) {

                                case Activity.RESULT_OK:
                                    result = "Message sent";
                                    break;
                                case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                                    result = "Sending failed";
                                    break;
                                case SmsManager.RESULT_ERROR_RADIO_OFF:
                                    result = "Radio off";
                                    break;
                                case SmsManager.RESULT_ERROR_NULL_PDU:
                                    result = "No PDU defined";
                                    break;
                                case SmsManager.RESULT_ERROR_NO_SERVICE:
                                    result = "No service";
                                    break;
                                }

                                handler.post(new Runnable() {

                                    @Override
                                    public void run() {
                                        if (result != "") {
                                            Toast toast = Toast.makeText(getActivity().getApplicationContext(),
                                                    result, Toast.LENGTH_LONG);
                                            toast.setGravity(Gravity.CENTER, 0, 0);
                                            toast.show();
                                            result = "";
                                        }
                                        dialog.dismiss();
                                    }
                                });
                            }

                        }, new IntentFilter(SENT));
                        //Register for Delivery event
                        getActivity().registerReceiver(new BroadcastReceiver() {

                            @Override
                            public void onReceive(Context context, Intent intent) {
                                handler.post(new Runnable() {

                                    @Override
                                    public void run() {
                                        Toast.makeText(getActivity().getApplicationContext(), "Delivered",
                                                Toast.LENGTH_LONG).show();
                                    }
                                });
                            }

                        }, new IntentFilter(DELIVERED));

                        //Send SMS
                        SmsManager smsManager = SmsManager.getDefault();
                        smsManager.sendTextMessage(getMobileNumber(contactUri), null,
                                textMessage.getText().toString(), sentPI, deliverPI);
                    } catch (Exception ex) {
                        final String exception = ex.getMessage().toString();
                        handler.post(new Runnable() {

                            @Override
                            public void run() {
                                Toast.makeText(getActivity().getApplicationContext(), exception,
                                        Toast.LENGTH_LONG).show();
                            }
                        });
                        ex.printStackTrace();
                        dialog.dismiss();
                    }

                }
            });
            th.start();
        }
        break;
    default:
        break;
    }
}