对于“帮助我起不来”应用程序之类的东西——是否有一种方法可以让用户设置联系电话,然后让应用程序在未来无需用户启动拨出的情况下调用该号码?我试过以下但似乎有问题:
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);
}
}
最佳答案
要获得无需使用拨号器即可调用电话并要求用户确认调用的权限,您必须设置 CALL_PHONE或 CALL_PRIVILEGED AndroidManifest.xml
文件中的权限取决于您的需要。
<uses-permission android:name="android.permission.CALL_PHONE" />
或
<uses-permission android:name="android.permission.CALL_PRIVILEGED" />
关于Android:没有用户初始化的来电号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3696922/