Java Code Examples for android.content.Intent#ACTION_CALL

The following examples show how to use android.content.Intent#ACTION_CALL . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void dispatchAction() {
    if (Intent.ACTION_CALL.equals(calloutAction)) {
        tManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);

        Intent call = new Intent(Intent.ACTION_CALL);
        call.setData(Uri.parse("tel:" + number));
        if (call.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(call, CALL_RESULT);
        } else {
            Toast.makeText(this, Localization.get("callout.failure.dialer"), Toast.LENGTH_SHORT).show();
            finish();
        }
    } else {
        Intent sms = new Intent(Intent.ACTION_SENDTO);
        sms.setData(Uri.parse("smsto:" + number));
        if (sms.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(sms, SMS_RESULT);
        } else {
            Toast.makeText(this, Localization.get("callout.failure.sms"), Toast.LENGTH_SHORT).show();
            finish();
        }
    }
}
 
Example 2
@Override
public void button911Clicked() {
    try {
        Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel://911"));
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        startActivity(callIntent);
    }
    catch(ActivityNotFoundException e)
    {
        Log.e("call", "Call failed", e);
    }

}
 
Example 3
Source Project: ToDay   File: HelpActivity.java    License: MIT License 5 votes vote down vote up
public void  calling(){
    Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:89860933"));
    if (ActivityCompat.checkSelfPermission(getBaseContext(), Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    startActivity(callIntent);
}
 
Example 4
@Override
public void onClick(View view) {
    ContactInfo ci = (ContactInfo) view.getTag();
    List<String> phones = ContactsWrapper.getInstance().getCSipPhonesContact(mContext, ci.contactId);
    boolean useCSip = true;
    String toCall = null;
    if(phones != null && phones.size() > 0) {
        toCall = phones.get(0);
    }else {
        List<Phone> cPhones = ContactsWrapper.getInstance().getPhoneNumbers(mContext, ci.contactId, ContactsWrapper.URI_ALLS);
        if(cPhones != null && cPhones.size() > 0) {
            toCall = cPhones.get(0).getNumber();
            useCSip = false;
        }
    }
    
    if(!TextUtils.isEmpty(toCall) ) {
        Cursor c = (Cursor) getItem((Integer) ci.userData);
        Long profileId = null;
        while(c.moveToPrevious()) {
            int cTypeIdx = c.getColumnIndex(ContactsWrapper.FIELD_TYPE);
            int cAccIdx = c.getColumnIndex(BaseColumns._ID);
            if(cTypeIdx >= 0 && cAccIdx >= 0) {
                if(c.getInt(cTypeIdx) == ContactsWrapper.TYPE_GROUP) {
                    profileId = c.getLong(cAccIdx);
                    break;
                }
            }
        }
        
        Intent it = new Intent(Intent.ACTION_CALL);
        it.setData(SipUri.forgeSipUri(useCSip ? SipManager.PROTOCOL_CSIP : SipManager.PROTOCOL_SIP, toCall));
        it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if(profileId != null) {
            it.putExtra(SipProfile.FIELD_ACC_ID, profileId);
        }
        mContext.startActivity(it);
    }
}
 
Example 5
Source Project: VoIpUSSD   File: USSDController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * get action call Intent
 *
 * @param uri     parsed uri to call
 * @param simSlot simSlot number to use
 */
@SuppressLint("MissingPermission")
private Intent getActionCallIntent(Uri uri, int simSlot) {
    // https://stackoverflow.com/questions/25524476/make-call-using-a-specified-sim-in-a-dual-sim-device
    final String simSlotName[] = {
            "extra_asus_dial_use_dualsim",
            "com.android.phone.extra.slot",
            "slot",
            "simslot",
            "sim_slot",
            "subscription",
            "Subscription",
            "phone",
            "com.android.phone.DialingMode",
            "simSlot",
            "slot_id",
            "simId",
            "simnum",
            "phone_type",
            "slotId",
            "slotIdx"
    };

    Intent intent = new Intent(Intent.ACTION_CALL, uri);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("com.android.phone.force.slot", true);
    intent.putExtra("Cdma_Supp", true);

    for (String s : simSlotName)
        intent.putExtra(s, simSlot);

    TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    if (telecomManager != null) {
        List<PhoneAccountHandle> phoneAccountHandleList = telecomManager.getCallCapablePhoneAccounts();
        if (phoneAccountHandleList != null && phoneAccountHandleList.size() > simSlot)
            intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", phoneAccountHandleList.get(simSlot));
    }

    return intent;
}
 
Example 6
Source Project: AndroidBasicProject   File: IntentUtil.java    License: MIT License 5 votes vote down vote up
/**
 * 直接拨号
 * 需要权限:android.permission.CALL_PHONE
 */
public static void call(@NonNull Context context, @NonNull String phoneNumber) {
    Intent intentPhone = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) ==
        PackageManager.PERMISSION_GRANTED) {
        context.startActivity(intentPhone);
    } else {
        Logger.e("no permission: android.permission.CALL_PHONE");
    }
}
 
Example 7
Source Project: openlauncher   File: ShareUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Call telephone number.
 * Non direct call, opens up the dialer and pre-sets the telephone number. User needs to press manually.
 * Direct call requires M permission granted, also add permissions to manifest:
 * <uses-permission android:name="android.permission.CALL_PHONE" />
 *
 * @param telNo      The telephone number to call
 * @param directCall Direct call number if possible
 */
@SuppressWarnings("SimplifiableConditionalExpression")
public void callTelephoneNumber(final String telNo, final boolean... directCall) {
    Activity activity = greedyGetActivity();
    if (activity == null) {
        throw new RuntimeException("Error: ShareUtil::callTelephoneNumber needs to be contstructed with activity context");
    }
    boolean ldirectCall = (directCall != null && directCall.length > 0) ? directCall[0] : true;


    if (android.os.Build.VERSION.SDK_INT >= 23 && ldirectCall && activity != null) {
        if (ContextCompat.checkSelfPermission(activity, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.CALL_PHONE}, 4001);
            ldirectCall = false;
        } else {
            try {
                Intent callIntent = new Intent(Intent.ACTION_CALL);
                callIntent.setData(Uri.parse("tel:" + telNo));
                activity.startActivity(callIntent);
            } catch (Exception ignored) {
                ldirectCall = false;
            }
        }
    }
    // Show dialer up with telephone number pre-inserted
    if (!ldirectCall) {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", telNo, null));
        activity.startActivity(intent);
    }
}
 
Example 8
private void HandleCalling(String callingData) {
    /*
    * Sample callingData:
    * 9841758496
    * */
    String phoneNumber = callingData.trim().replace("\n", "");
    if (!phoneNumber.equals("")) {
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:" + phoneNumber));
        intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
        _ctx.startActivity(intent);
    }
}
 
Example 9
/**
 * 调用系统打电话界面
 *
 * @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 = new Intent(Intent.ACTION_CALL, uri);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
 
Example 10
private void callNumber(String number) {
	if (TextUtils.isEmpty(number) || null == number) {
		return;
	}
	
	Uri uri = Uri.parse("tel:" + Uri.encode(number));
	Intent intent = new Intent(Intent.ACTION_CALL, uri);
	startActivity(intent);
	finish();
}
 
Example 11
private void call(int i) {
    String phone;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission(android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(new String[]{android.Manifest.permission.CALL_PHONE}, PERMISSIONS_REQUEST_PHONE_CALL);
    } else {
        phone = number[i];
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:+91" + phone));
        startActivity(intent);
    }

}
 
Example 12
public static void requestCall(Context context, String number) {
    if (!number.equals("false") && !number.equals("")) {
        Intent intent = new Intent(Intent.ACTION_CALL);
        intent.setData(Uri.parse("tel:" + number));
        context.startActivity(intent);
    }
}
 
Example 13
Source Project: testing-cin   File: DialerActivity.java    License: MIT License 4 votes vote down vote up
private Intent createCallIntentFromNumber() {
    final Intent intentToCall = new Intent(Intent.ACTION_CALL);
    String number = mCallerNumber.getText().toString();
    intentToCall.setData(Uri.parse("tel:" + number));
    return intentToCall;
}
 
Example 14
void call(long phoneNumber) {
    Intent intent = new Intent(Intent.ACTION_CALL);
    intent.setData(Uri.parse("tel:" + phoneNumber));
    intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);
}
 
Example 15
void doCallPhone() {
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:10086"));
    startActivity(intent);
}
 
Example 16
Source Project: XERUNG   File: Comman.java    License: Apache License 2.0 4 votes vote down vote up
public void callPhone(String number,Context context){
	 Intent callIntent = new Intent(Intent.ACTION_CALL);
     callIntent.setData(Uri.parse("tel:" + number));
	 context.startActivity(callIntent);
}
 
Example 17
Source Project: Pigeon   File: PhoneUtil.java    License: MIT License 4 votes vote down vote up
/**
 * 打电话, 不弹出界面,直接拨打 需要权限
 * <uses-permission android:name="android.permission.CALL_PHONE" />
 */
public static void call(Context context, String number) {
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + number));
    context.startActivity(intent);
}
 
Example 18
@Override
public void run() {
    //注册广播接收者
    unRegisterReceiver();
    mCallReceiver = new CallAndSmsReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_NEW_OUTGOING_CALL);
    intentFilter.addAction(SMS_SEND_ACTION);
    mContext.registerReceiver(mCallReceiver, intentFilter);

    // EventBus.getDefault().post(new RecordUpdateEvent(RecordUpdateEvent.RECORD_IDLE));
    switch (type) {
        case 0:     //电话
            Intent speechIntent = new Intent(mContext, AssistantService.class);
            speechIntent.putExtra(AssistantService.CMD, AssistantService.ServiceCmd.STOP_VOICE_MODE);
            mContext.startService(speechIntent);
            Log.i("LingJu", "手机厂商:" + Build.MANUFACTURER);
            //由于华为、小米、三星手机无法直接呼出紧急电话,所以在该号码前加区号(魅族可以)
            if (number.length() == 3 && number.matches("^(110|119|120)$") && !"Meizu".equals(Build.MANUFACTURER)) {
                String city = Setting.formatCity(Setting.getAddress().getCity());
                number = CallAndSmsDao.getInstance(mContext).getZipCode(city) + number;
            }
            // PermissionUtils.checkPermission(mContext, PermissionUtils.OP_CALL_PHONE);
            Intent icall = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + this.number));
            icall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
            mContext.startActivity(icall);

            break;
        case 1:     //短信
            // PermissionUtils.checkPermission(mContext, PermissionUtils.OP_SEND_SMS);
            SmsManager smsManager = SmsManager.getDefault();
            if (content != null && content.length() > 0) {
                content += "-发自小灵机器人";
                //切分短信,每七十个汉字为一条短信,不足七十就只有一条:返回的是字符串的List集合
                List<String> texts = smsManager.divideMessage(content);
                //发送短信
                PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, new Intent(SMS_SEND_ACTION), 0);
                for (String tt : texts) {
                    phoneNumber = number;
                    smsContent = tt;
                    smsManager.sendTextMessage(number, null, tt, pi, null);
                }
            }
            break;
    }
    /* 停止识别、合成 */
    Intent intent = new Intent(mContext, AssistantService.class);
    intent.putExtra(AssistantService.CMD, AssistantService.ServiceCmd.SEND_TO_ROBOT_FOR_END_TASK);
    intent.putExtra(AssistantService.TRY_TO_WAKEUP, false);
    mContext.startService(intent);
    if (EventBus.getDefault().hasSubscriberForEvent(CallTaskEvent.class)) {
        EventBus.getDefault().post(new CallTaskEvent(CallTaskEvent.STATE_END));
    }

    cancelCommunicationTimer();
}
 
Example 19
Source Project: Android-utils   File: IntentUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 返回一个用来拨打指定手机号码的意图
 *
 * @param phoneNumber 手机号码
 * @param isNewTask   是否作为 NEW TASK 启动指定的应用
 * @return 意图
 */
@RequiresPermission(CALL_PHONE)
public static Intent getCallIntent(final String phoneNumber, final boolean isNewTask) {
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
    return getIntent(intent, isNewTask);
}
 
Example 20
Source Project: KeyboardView   File: SystemUtil.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 直接拨打电话
 *
 * @param context
 * @param phoneNumber
 */
public static void actionCall(Context context, String phoneNumber) {
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumber));
    context.startActivity(intent);
}