我正在构建一个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
答案 0 :(得分: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" />
for&lt; =棒棒糖设备
答案 1 :(得分:0)
我猜它是关于targetSdkVersion和using permissions的。将targetSdkVersion更改为Android 5.1(API级别22)或更低版本。它可能解决了这个问题。
答案 2 :(得分: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));
答案 3 :(得分: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提供的上述方法