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:Main.java

public static void callPhone(Context context, String number) {
    String tel = "tel:" + number;
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(tel));
    context.startActivity(intent);//from  w ww . ja  v  a2 s . c  om
}

From source file:MainActivity.java

public void dialPhone(View view) {
    if (checkPermission("android.permission.CALL_PHONE")) {
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:0123456789"));
        startActivity(intent);/* w w  w.j  a  v  a 2 s .co  m*/
    }
}

From source file:org.mitre.svmp.client.IntentHandler.java

public static void inspect(SVMPProtocol.Response response, Context context) {
    SVMPProtocol.Intent intent = response.getIntent();
    switch (intent.getAction()) {
    case ACTION_DIAL:
        Log.d(TAG, String.format("Received 'call' Intent for number '%s'", intent.getData()));
        int telephonyEnabled = isTelephonyEnabled(context);
        if (telephonyEnabled == 0) {
            Intent call = new Intent(Intent.ACTION_CALL);
            call.setData(Uri.parse(intent.getData()));
            context.startActivity(call);
        } else {/*from  w  w  w .ja  v a  2 s  .  c o  m*/
            // phone calls are not supported on this device; send a Toast to
            // the user to let them know
            Toast toast = Toast.makeText(context, telephonyEnabled, Toast.LENGTH_LONG);
            toast.show();
        }
        break;
    case ACTION_VIEW:
        String jsonStr = intent.getData().toString();
        JSONObject jObj = null;
        String message = null;
        try {
            jObj = new JSONObject(jsonStr);
            message = jObj.getString("message");

            if (jObj != null && message != null) {
                switch (message) {
                case "keyboardStarted":

                    InputMethodManager imm = (InputMethodManager) context
                            .getSystemService(context.INPUT_METHOD_SERVICE);
                    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                    break;

                case "appInstalled":

                    String success = jObj.getString("success");
                    String packageName = jObj.getString("packageId");

                    if (success != null) {
                        if (success.equals("true"))
                            startApp(packageName, context);
                    }
                    break;

                default:
                    break;
                }
            }

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        break;
    default:
        break;
    }
}

From source file:com.jay.util.PhoneUtil.java

/**
 * ??//  w ww. j  a v a2s. c om
 *
 * @param context     
 * @param phoneNumber ??
 */
public static void callPhones(Context context, String phoneNumber) {
    if (phoneNumber == null || phoneNumber.length() < 1) {
        return;
    }
    Uri uri = Uri.parse("tel:" + phoneNumber);
    Intent intent = null;
    //??????
    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        intent = new Intent(Intent.ACTION_DIAL, uri);
    } else {
        intent = new Intent(Intent.ACTION_CALL, uri);
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}

From source file:MainActivity.java

public void dialPhone(View view) {
    if (checkCallPermission()) {
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:0123456789"));
        startActivity(intent);/*from  w  w w .  j  a  va  2 s .c o m*/
    }
}

From source file:com.code19.library.SystemUtils.java

public static void callPhone(Activity activity, String phoneNumber) {
    if (activity != null && !TextUtils.isEmpty(phoneNumber)) {
        if (ActivityCompat.checkSelfPermission(activity,
                Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            return;
        }/*from w  w w  .  j  ava 2 s . c  o m*/
        activity.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber)));
    }
}

From source file:com.android.common.util.IntentUtils.java

/**
 * Call up, requires Permission "android.permission.CALL_PHONE"
 *
 * @param context//w w  w . j  a v a  2  s  . c om
 * @param number
 */
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 sendNotification(RemoteMessage.Notification messageNotification, Map messageData) {
    Log.d(TAG, "Entering Send notification");

    Intent callIntent = new Intent(Intent.ACTION_CALL,
            Uri.parse("tel:" + (String) messageData.get("phoneNumber")));
    callIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, callIntent, PendingIntent.FLAG_ONE_SHOT);

    String messageType = (String) messageData.get("type");
    Log.d(TAG, "messageType: " + messageType);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = null;

    if ("call".equals(messageType)) {
        Log.d(TAG, "inside call: ");
        notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(android.R.drawable.stat_notify_missed_call)
                .setContentTitle(messageNotification.getTitle()).setContentText(messageNotification.getBody())
                .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent)
                .addAction(0, "Call", pendingIntent);
    } else {/*from ww  w .jav  a  2 s. co m*/
        Log.d(TAG, "inside sms: ");
        notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(android.R.drawable.sym_action_email)
                .setContentTitle(messageNotification.getTitle()).setContentText(messageNotification.getBody())
                .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent);
    }

    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

From source file:library.artaris.cn.library.utils.SystemUtils.java

/**
 * ???//from   w w w .j a  va  2s  .c  o  m
 * @param activity
 * @param phoneNumber
 */
public static void callPhone(Activity activity, String phoneNumber) {
    if (activity != null && !TextUtils.isEmpty(phoneNumber)) {
        if (ActivityCompat.checkSelfPermission(activity,
                Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        activity.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber)));
    }
}

From source file:com.mobileglobe.android.customdialer.common.CallUtil.java

/**
 * Return an Intent for making a phone call. A given Uri will be used as is (without any
 * sanity check).//from  ww w .  j  ava2  s .c  om
 */
public static Intent getCallIntent(Uri uri) {
    return new Intent(Intent.ACTION_CALL, uri);
}