由网友(末路狂澜)分享简介:有关有点像'的帮助,我也上不了'的应用程序 - 有没有办法为用户设置了联系电话,然后对应用程序调用,在未来的数而无需用户启动的拨出?我已经试过以下,但似乎有一个问题:私人无效callPhone(){如果(phoneNumber.length()大于0){尝试 {意向意图=新的意图(Intent.ACTION_CALL)...
有关有点像'的帮助,我也上不了'的应用程序 - 有没有办法为用户设置了联系电话,然后对应用程序调用,在未来的数而无需用户启动的拨出?我已经试过以下,但似乎有一个问题:
私人无效callPhone(){
如果(phoneNumber.length()大于0){
尝试 {
意向意图=新的意图(Intent.ACTION_CALL);
intent.setData(Uri.parse(电话:+ phoneNumber的));
startActivity(意向);
}赶上(例外五){
Toast.makeText(getApplicationContext(),问题主叫号码。,Toast.LENGTH_LONG).show();
}
// startActivityForResult(新意图(Intent.ACTION_CALL,Uri.parse(电话:++ phoneNumber的)),1);
}
}
解决方案
要得到你需要拨打电话,而无需使用拨号器,并要求用户确认呼叫的权限,必须设置无论是CALL_PHONE或CALL_PRIVILEGED在的AndroidManifest.xml
文件的权限根据您的需求。
<使用-权限的Android:名称=android.permission.CALL_PHONE/>
或
<使用-权限的Android:名称=android.permission.CALL_PRIVILEGED/>
For something like a 'help I can't get up' app -- is there a way for a user to set a contact number, and then for the app to call that number in the future WITHOUT the user initiating the dialout? I've tried the below but there seems to be a problem:
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);
}
}
解决方案
To get the permission that you need to place calls without using the dialer and requiring the user to confirm the call, you must set either the CALL_PHONE or CALL_PRIVILEGED permissions in your AndroidManifest.xml
file depending on your needs.
<uses-permission android:name="android.permission.CALL_PHONE" />
or
<uses-permission android:name="android.permission.CALL_PRIVILEGED" />
相关推荐
最新文章