安卓:主叫号码,而无需用户初始化? [英] Android: calling number without user init?

查看:175
本文介绍了安卓:主叫号码,而无需用户初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关有点像'的帮助,我也上不了'的应用程序 - 有没有办法为用户设置了联系电话,然后对应用程序调用,在未来的数而无需用户启动的拨出?我已经试过以下,但似乎有一个问题:

 私人无效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);
            }

        }
 

解决方案

要得到你需要拨打电话,而无需使用拨号器,并要求用户确认呼叫的权限,必须设置无论是<一个href="http://developer.android.com/reference/android/Manifest.permission.html#CALL_PHONE">CALL_PHONE或<一href="http://developer.android.com/reference/android/Manifest.permission.html#CALL_PRIVILEGED">CALL_PRIVILEGED在的Andr​​oidManifest.xml 文件的权限根据您的需求。

 &LT;使用-权限的Andr​​oid:名称=android.permission.CALL_PHONE/&GT;
 

 &LT;使用-权限的Andr​​oid:名称=android.permission.CALL_PRIVILEGED/&GT;
 

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" />

这篇关于安卓:主叫号码,而无需用户初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆