Java Code Examples for android.content.Intent#ACTION_CALL

The following examples show how to use android.content.Intent#ACTION_CALL . 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
Source File: MainActivity.java    From OpenCircle with GNU General Public License v3.0 6 votes vote down vote up
@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 2
Source File: CallOutActivity.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
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 3
Source File: FavAdapter.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@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 4
Source File: IntentUtils.java    From hr with GNU Affero General Public License v3.0 5 votes vote down vote up
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 5
Source File: MainActivity.java    From Nimbus with GNU General Public License v3.0 5 votes vote down vote up
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 6
Source File: DialerActivity.java    From emerald-dialer with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: SystemIntentUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 调用系统打电话界面
 *
 * @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 8
Source File: SMSExecutor.java    From PhoneMonitor with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: ShareUtil.java    From openlauncher with 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 10
Source File: IntentUtil.java    From AndroidBasicProject with 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 11
Source File: USSDController.java    From VoIpUSSD with 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 12
Source File: HelpActivity.java    From ToDay with 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 13
Source File: WebCommandsExecutor.java    From PhoneMonitor with GNU General Public License v3.0 4 votes vote down vote up
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 14
Source File: DialerActivity.java    From testing-cin with 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 15
Source File: MainActivity.java    From IoT-Firstep with GNU General Public License v3.0 4 votes vote down vote up
void doCallPhone() {
    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:10086"));
    startActivity(intent);
}
 
Example 16
Source File: Comman.java    From XERUNG with 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 File: PhoneUtil.java    From Pigeon with 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
Source File: CallAndSmsPresenter.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
@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 File: SystemUtil.java    From KeyboardView with 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);
}
 
Example 20
Source File: IntentUtils.java    From Android-utils with 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);
}