-4

我正在构建一个 android 应用程序,在该应用程序中,我使用以下代码拨打*123*1# 之类的 USSD 代码。

context.startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:*123*1" + Uri.encode("#"))).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

我面临的问题是我的应用程序正在关闭。请参阅以下日志:

03-06 17:49:33.404 4937-4937/**** D/ViewRootImpl: ViewPostImeInputStage processPointer 0
03-06 17:49:33.614 4937-4937/**** D/ViewRootImpl: ViewPostImeInputStage processPointer 1
03-06 17:49:33.654 4937-4937/**** D/USSDCode: *123*1#

                                                     --------- beginning of system
03-06 17:49:33.734 4937-4937/**** D/isAccessibility: false
             03-06 17:49:33.734 4937-4937/**** D/isMyWise1: false
03-06 17:49:33.734 4937-4937/**** D/isMyWise3: Access
03-06 17:49:33.774 4937-4937/**** I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@e5b7389 time:17108783
03-06 17:49:35.464 4937-4937/**** V/ActivityThread: updateVisibility : ActivityRecord{81dd657 token=android.os.BinderProxy@e5b7389 {****/com.databacklibrary.SIMBalanceActivity}} show : true
03-06 17:49:38.124 4937-4937/**** D/isAccessibility: false
03-06 17:49:38.124 4937-4937/**** D/isMyWise1: false
03-06 17:49:38.124 4937-4937/**** D/isMyWise3: Access
03-06 17:49:38.194 4937-4937/**** I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@e5b7389 time:17113201
03-06 17:49:38.524 4937-4937/**** D/USSDCodeMsg: onAccessibilityEvent
03-06 17:49:38.524 4937-4937/**** E/Alert1: 32
03-06 17:49:38.524 4937-4937/**** E/Alert2: com.android.phone
03-06 17:49:38.524 4937-4937/**** E/Alert3: null
03-06 17:49:38.524 4937-4937/**** E/Alert4: android.app.ProgressDialog
03-06 17:49:38.524 4937-4937/**** E/Alert5: [USSD code running...]
03-06 17:49:38.764 4937-4937/**** V/ActivityThread: updateVisibility : ActivityRecord{81dd657 token=android.os.BinderProxy@e5b7389 {****/com.databacklibrary.SIMBalanceActivity}} show : true
03-06 17:49:40.384 4937-4937/**** D/USSDCodeMsg: onAccessibilityEvent
 03-06 17:49:40.384 4937-4937/**** E/Alert1: 32
03-06 17:49:40.384 4937-4937/**** E/Alert2: com.android.phone
03-06 17:49:40.384 4937-4937/**** E/Alert3: null
03-06 17:49:40.384 4937-4937/**** E/Alert4: com.android.phone.MMIDialogActivity
03-06 17:49:40.384 4937-4937/**** E/Alert5: [Phone]
03-06 17:49:40.394 4937-4937/**** D/USSDCodeMsg: onAccessibilityEvent
03-06 17:49:40.394 4937-4937/**** E/Alert1: 32
03-06 17:49:40.394 4937-4937/**** E/Alert2: com.android.phone
03-06 17:49:40.394 4937-4937/**** E/Alert3: null
03-06 17:49:40.394 4937-4937/**** E/Alert4: android.app.AlertDialog
03-06 17:49:40.394 4937-4937/**** E/Alert5: [Connection problem or invalid MMI code., OK]
03-06 17:49:40.404 4937-4937/**** D/isAccessibility: false
03-06 17:49:40.404 4937-4937/**** D/isMyWise1: false
03-06 17:49:40.404 4937-4937/**** D/isMyWise3: Access
03-06 17:49:40.444 4937-4937/**** I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@e5b7389 time:17115454
03-06 17:49:40.544 4937-4937/**** D/ViewRootImpl: ViewPostImeInputStage processKey 0
03-06 17:49:40.544 4937-4937/**** D/ViewRootImpl: ViewPostImeInputStage processKey 1
03-06 17:49:41.254 4937-4937/**** D/ViewRootImpl: #3 mView = null
4

4 回答 4

1

如果是 >= marshmallow,你可以这样尝试

int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE);

    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(
                this,
                new String[]{Manifest.permission.CALL_PHONE},
                "123");
    } else {
        startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse("tel:*123#")));
    }

检查权限

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    switch (requestCode) {

        case 123:
            if ((grantResults.length > 0) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
               startActivity(new Intent(Intent.ACTION_CALL).setData(Uri.parse("tel:*123#")));
            } else {
                Log.d("TAG", "Call Permission Not Granted");
            }
            break;

        default:
            break;
    }
}

并且不要忘记在清单中添加权限

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

对于 < = 棒棒糖设备

于 2017-03-06T12:14:18.880 回答
0

试试这个购买调用函数调用()

public void call() {   
        Intent callIntent = new Intent(Intent.ACTION_CALL);          
        callIntent.setData(Uri.parse("tel:"+phone));          
        startActivity(callIntent);  
}

或者你可以试试这个

 context.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:*123*1" + Uri.encode("#"))).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
于 2017-03-06T12:40:21.433 回答
0
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:" + number));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

如果您想打开拨号键盘,则无需许可,否则请执行@Nitesh Mishra 提供的上述方法

于 2017-03-06T12:48:08.823 回答
0

我猜它与 targetSdkVersion 和使用权限有关。将 targetSdkVersion 更改为 Android 5.1(API 级别 22)或更低版本。它可能会解决问题。

于 2017-03-06T12:33:04.413 回答