Android:如何在没有用户初始化的情况下拨打电话?

3

对于类似“帮助我起床”的应用程序,用户是否可以设置联系电话,并让应用程序在未经用户启动的情况下将来拨打该号码? 我尝试了以下操作,但似乎存在问题:

 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);
            }

        }
1个回答

5

要想在不使用拨号器并且无需用户确认的情况下进行呼叫,您需要在AndroidManifest.xml文件中设置CALL_PHONECALL_PRIVILEGED权限,具体取决于您的需求。

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

或者

<uses-permission android:name="android.permission.CALL_PRIVILEGED" />

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接