Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android以编程方式进行调用,而不显示选择器_Android_Call_Skype - Fatal编程技术网

Android以编程方式进行调用,而不显示选择器

Android以编程方式进行调用,而不显示选择器,android,call,skype,Android,Call,Skype,我的设备已安装Skype。应用程序执行以下代码: Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + sMyNumber)); startActivityForResult(callIntent, REQUEST_CALL); 但是,弹出窗口询问是否应该使用电话或Skype完成操作 是否可以在代码中指定应该使用哪一个,以便用户不必选择?也许此代

我的设备已安装Skype。应用程序执行以下代码:

    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + sMyNumber));
    startActivityForResult(callIntent, REQUEST_CALL);
但是,弹出窗口询问是否应该使用电话或Skype完成操作


是否可以在代码中指定应该使用哪一个,以便用户不必选择?

也许此代码可以帮助您:

List<ResolveInfo> activityList = pm.queryIntentActivities(videoIntent, 0);
for (int i = 0; i < activityList.size(); i++) 
{
    ResolveInfo app = activityList.get(i);
    //search for your app

    callIntent.setClassName(app.activityInfo.packageName, app.activityInfo.name);
}
List activityList=pm.querytentActivities(videoIntent,0);
对于(int i=0;i

但在手机上请求应用程序有点危险,因为应用程序可能会更改其软件包名称,这将在将来破坏您的应用程序。

要始终使用手机应用程序拨打电话,请添加以下行:

    callIntent.setClassName("com.android.phone", "com.android.phone.OutgoingCallBroadcaster");

试试这个代码对我有用

公共void onClick(视图){

//监控电话通话状态 私有类PhoneCallListener扩展了PhoneStateListener{

    String TAG = "LOGGING PHONE CALL";

    private boolean phoneCalling = false;

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {

        if (TelephonyManager.CALL_STATE_RINGING == state) {
            // phone ringing
            Log.i(TAG, "RINGING, number: " + incomingNumber);
        }

        if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
            // active
            Log.i(TAG, "OFFHOOK");

            phoneCalling = true;
        }

        // When the call ends launch the main activity again
        if (TelephonyManager.CALL_STATE_IDLE == state) {

            Log.i(TAG, "IDLE");

            if (phoneCalling) {

                Log.i(TAG, "restart app");

                // restart app
                Intent i = getBaseContext().getPackageManager()
                        .getLaunchIntentForPackage(
                                getBaseContext().getPackageName());

                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);

                phoneCalling = false;
            }

        }
    }
}

这可能会在将来中断-不推荐。它会在许多设备上中断,比如5.0+三星高级手机。这是如何防止选择器出现的?您是否在一个有多个应用程序能够处理该意图的系统上尝试过它?这个答案与问题中提到的完全相同,它不起作用。为什么人们会这样做写答案而不看问题?你在Pawel解决了这个问题吗?
    String TAG = "LOGGING PHONE CALL";

    private boolean phoneCalling = false;

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {

        if (TelephonyManager.CALL_STATE_RINGING == state) {
            // phone ringing
            Log.i(TAG, "RINGING, number: " + incomingNumber);
        }

        if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
            // active
            Log.i(TAG, "OFFHOOK");

            phoneCalling = true;
        }

        // When the call ends launch the main activity again
        if (TelephonyManager.CALL_STATE_IDLE == state) {

            Log.i(TAG, "IDLE");

            if (phoneCalling) {

                Log.i(TAG, "restart app");

                // restart app
                Intent i = getBaseContext().getPackageManager()
                        .getLaunchIntentForPackage(
                                getBaseContext().getPackageName());

                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(i);

                phoneCalling = false;
            }

        }
    }
}