你好,我想使按鈕,請允許我自動呼叫自動呼叫按按鈕
這是我想提出調用實際上
String number = "1234";
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel",number,null));
startActivity(intent);
但我必須確認按以撥打電話撥號程序中的電話圖標。是否有可能使其自動?
你好,我想使按鈕,請允許我自動呼叫自動呼叫按按鈕
這是我想提出調用實際上
String number = "1234";
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel",number,null));
startActivity(intent);
但我必須確認按以撥打電話撥號程序中的電話圖標。是否有可能使其自動?
使用行爲Intent.ACTION_CALL
,因此,更改此:
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel",number,null));
有了這個:
Intent intent = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel",number,null));
添加權限:
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.CALL_PHONE)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.CALL_PHONE)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CALL_PHONE},
1);
}
}
手柄權限:
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String permissions[],
@NonNull int[] grantResults) {
switch (requestCode) {
case 1: {
if ((grantResults.length > 0) && (grantResults[0] +
grantResults[1]) == PackageManager.PERMISSION_GRANTED) {
//Call whatever you want
}
}
}
}
試試這個代碼,它會幫助你。在烏里
Uri numberUri = Uri.parse("tel:"+number);
代碼
String number = "1234";
獲取號碼撥號
Intent callIntent = new Intent(Intent.ACTION_DIAL, numberUri);
startActivity(callIntent);
代碼調用
Intent callIntent = new Intent(Intent.ACTION_CALL, numberUri);
startActivity(callIntent);
編輯
在棉花糖,你必須採取運行時間調用權限。 如果權限被拒絕,您不能撥打電話。
現在有其他的解決方案,我想給你。
您可以在6.0以上的自動呼叫而不要求運行時間權限。但爲此,您必須將
targetSdkVersion
設置爲19
或低於22
。那麼將會發生什麼,全部權限將被自動啓用,因爲Android OS
將把它作爲舊應用程序並允許而不需要運行時間權限。但還有一個問題。通過繼續設置手動禁用權限後,它將不起作用。
你接受的我的回答人 – W4R10CK