我想拨打并获得拨打的 USSD 代码响应。这是我的代码。但是当我运行时,吐司上没有显示任何响应。
private void ussdResponse(String completeCode) {
TelephonyManager manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
if (checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED || checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CALL_PHONE}, requestCode);
ActivityCompat.requestPermissions(MainActivity.this , new String[]{Manifest.permission.READ_PHONE_STATE},requestCode);
return;
}
manager.sendUssdRequest(completeCode, new TelephonyManager.UssdResponseCallback() {
@Override
public void onReceiveUssdResponse(TelephonyManager telephonyManager, String request, CharSequence response) {
super.onReceiveUssdResponse(telephonyManager, request, response);
Toast.makeText(MainActivity.this, "Success", Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "USSD Result"+response.toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onReceiveUssdResponseFailed(TelephonyManager telephonyManager, String request, int failureCode) {
super.onReceiveUssdResponseFailed(telephonyManager, request, failureCode);
Toast.makeText(MainActivity.this, "Failed", Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "USSD Response Failed.", Toast.LENGTH_SHORT).show();
}
}, new Handler());
}
compleCode包含 USSD 代码。但是 Toast 什么也没显示。任何人都可以找到我的解决方案吗?或者有没有其他方法可以在我的应用程序中获取拨打的 USSD 响应?
侃侃无极
相关分类