[英]I want my Android App to get EditText value, then join # symbol to it and dial USSD code - but its just calling
[英]Android Studio - Execute USSD code in Dial Pad
我的代码现在有问题,我不知道是否有人可以帮助我。 我需要在拨号盘中运行USSD代码,并且正在使用以下代码:
Intent i = new Intent(Intent.ACTION_DIAL);
i.setData(Uri.parse("tel:"+ Uri.encode("##873283#")));
startActivity(i);
这样就可以打开拨号盘,并且什么也不做。 如果我手动插入,USSD代码将正确运行。
当心此USSD代码,无需调用按钮即可执行。
您可以在我手动运行代码的地方查看此视频: 视频1
从应用程序运行代码(它将收到命令“ update”并执行我发布的代码): 视频2
我认为只有在有按键的情况下才执行代码。 这是问题吗? 有一种方法可以模拟吗?
非常感谢
如果要在没有用户交互的情况下直接发起呼叫,则可以使用操作Intent.ACTION_CALL。 由于最新SDK的安全性,您最初必须要求一些权限:
private void dialNumber(final String phoneNumber) {
//permission is automatically granted on sdk<23 upon installation
if (Build.VERSION.SDK_INT >= 23) {
//Check if you have permissions to execute a call (number or USSD)
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
Log.v("TAG","Permission is granted");
startActivity(new Intent(ACTION_CALL, Uri.fromParts("tel", phoneNumber, null)));
} else {
//Request permissions if we don't have them
Log.v("TAG","Permission is revoked");
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.CALL_PHONE}, 1);
startActivity(new Intent(ACTION_CALL, Uri.fromParts("tel", phoneNumber, null)));
}
}
else {
Log.v("TAG","Permission is granted");
startActivity(new Intent(ACTION_CALL, Uri.fromParts("tel", phoneNumber, null)));
}
}
在您的AndroidManifest.xml中添加以下权限(在应用程序标记之前):
<uses-permission android:name="android.permission.CALL_PHONE" />
在需要使用该方法时调用该方法,并将电话号码作为字符串传递:
dialNumber("##323232#");
要么
dialNumber(123456789.toString());
我现在 在这里 拍摄的视频
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.