Java 手机不打有意向的电话

Java 手机不打有意向的电话,java,android,android-intent,Java,Android,Android Intent,我的行动电话有点问题。我把许可证放在清单上,但它不起作用。我按下按钮打电话,但什么也没发生。我正在制作的应用程序具有多种用途,因此代码不在MainActivity中。我不知道它是否有用,但我使用的是API 28。 谢谢你的阅读 清单: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ex

我的行动电话有点问题。我把许可证放在清单上,但它不起作用。我按下按钮打电话,但什么也没发生。我正在制作的应用程序具有多种用途,因此代码不在MainActivity中。我不知道它是否有用,但我使用的是API 28。 谢谢你的阅读

清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.intentsimplicitas">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".SmsActivity"></activity>
    <activity android:name=".DialActivity" />
    <activity android:name=".WaysActivity" />
    <activity android:name=".MapActivity" />
    <activity android:name=".PageActivity" />
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
发件人:

请求许可:

// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
        Manifest.permission.CALL_PHONE)
        != PackageManager.PERMISSION_GRANTED) {

    // Permission is not granted
    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
            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; request the permission
        ActivityCompat.requestPermissions(thisActivity,
                new String[]{Manifest.permission.CALL_PHONE},
                MY_PERMISSIONS_REQUEST_CALL_PHONE);

        // MY_PERMISSIONS_REQUEST_CALL_PHONE is an
        // app-defined int constant. The callback method gets the
        // result of the request.
    }
} else {
    // Permission has already been granted
}
验证:

@Override
public void onRequestPermissionsResult(int requestCode,
        String[] permissions, int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_CALL_PHONE: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // permission was granted, yay! Do the
                // contacts-related task you need to do.
            } else {
                // permission denied, boo! Disable the
                // functionality that depends on this permission.
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request.
    }
}
发件人:

请求许可:

// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
        Manifest.permission.CALL_PHONE)
        != PackageManager.PERMISSION_GRANTED) {

    // Permission is not granted
    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
            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; request the permission
        ActivityCompat.requestPermissions(thisActivity,
                new String[]{Manifest.permission.CALL_PHONE},
                MY_PERMISSIONS_REQUEST_CALL_PHONE);

        // MY_PERMISSIONS_REQUEST_CALL_PHONE is an
        // app-defined int constant. The callback method gets the
        // result of the request.
    }
} else {
    // Permission has already been granted
}
验证:

@Override
public void onRequestPermissionsResult(int requestCode,
        String[] permissions, int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_CALL_PHONE: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // permission was granted, yay! Do the
                // contacts-related task you need to do.
            } else {
                // permission denied, boo! Disable the
                // functionality that depends on this permission.
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request.
    }
}
你可以通过意图来做

public void dialClick (View v) {
    phone = edtPhone.getText().toString();
    Uri uri = Uri.parse("tel: " + phone);
    it = new Intent(Intent.ACTION_DIAL);
    it.setData(uri);
    startActivity(it);
}

您可以通过Intent完成

public void dialClick (View v) {
    phone = edtPhone.getText().toString();
    Uri uri = Uri.parse("tel: " + phone);
    it = new Intent(Intent.ACTION_DIAL);
    it.setData(uri);
    startActivity(it);

}

您需要在运行时添加权限才能进行调用,我建议使用以下库,因为在执行时实现权限要容易得多


您需要在运行时添加权限才能进行调用,我建议使用以下库,因为在执行时实现权限要容易得多


CALL\u PHONE
是一个
危险的
权限,所以你需要在运行时使用
requestPermissions()
请求它。谢谢,我会试试它的
CALL\u PHONE
是一个
危险的
权限,所以你需要在运行时使用
requestPermissions()
请求它。谢谢,我会试试它,但它会进入我的手机键盘,屏幕上有号码我试过拨号,但它会进入我的手机键盘,屏幕上有号码