Android:没有用户init的主叫号码?

gri*_*rks 3 android phone-call android-intent

对于像"帮助我无法起床"的应用程序 - 用户是否有办法设置联系号码,然后让应用程序在将来拨打该号码而不启动用户启动拨出?我尝试过以下但似乎有一个问题:

 private void callPhone(){
            if(phoneNumber.length()>0){
                try {
                       Intent intent = new Intent(Intent.ACTION_CALL);
                       intent.setData(Uri.parse("tel:"+phoneNumber));
                       startActivity(intent);
                    } catch (Exception e) {
                        Toast.makeText(getApplicationContext(), "Problem calling number.", Toast.LENGTH_LONG).show();
                    }
                //startActivityForResult(new Intent(Intent.ACTION_CALL, Uri.parse("tel:+"+phoneNumber)), 1);
            }

        }
Run Code Online (Sandbox Code Playgroud)

Bri*_*ian 5

要获得在不使用拨号程序的情况下拨打电话并要求用户确认呼叫所需的权限,您必须AndroidManifest.xml根据需要在文件中设置CALL_PHONECALL_PRIVILEGED权限.

<uses-permission android:name="android.permission.CALL_PHONE" />
Run Code Online (Sandbox Code Playgroud)

要么

<uses-permission android:name="android.permission.CALL_PRIVILEGED" />
Run Code Online (Sandbox Code Playgroud)