最近我和我的家人搬到了一所新房子,我们的电话服务有些问题。 与所有隔离区一样,我有一个备用的,哈哈,我开始开发android应用。 我读到有关如何检查信号强度的信息(我们都有三星设备),并且遇到了USSD代码*#0011#。 经过一天的研究,我找到了USSD API,并开始编写一个应用程序,该应用程序最终将(向我的手机)显示单元的信号强度。 当我发送USSD代码时,回调总是失败,将调用onReceiveUssdResponseFailed()。 有帮助吗?
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, 0);
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Handler handler = new Handler();
TelephonyManager.UssdResponseCallback responseCallback = 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_LONG).show();
}
@Override
public void onReceiveUssdResponseFailed(TelephonyManager telephonyManager, String request, int failureCode) {
super.onReceiveUssdResponseFailed(telephonyManager, request, failureCode);
Toast.makeText(MainActivity.this, "Failed " + request, Toast.LENGTH_LONG).show();
}
};
try {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
telephonyManager.sendUssdRequest("*#0011#", responseCallback, handler);
} catch (NullPointerException e){
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
evelop android应用。我读到有关如何检查信号强度的信息(我们都有三星设备),并且遇到了USSD代码*#0011#。经过一天的研究,我找到了USSD API,并开始编写一个应用程序,该应用程序最终将(向我的手机)显示单元的信号强度。当我发送USSD代码时,回调总是失败,将调用onReceiveUssdResponseFailed()。有帮助吗?
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
requestPermissions(new String[]{Manifest.permission.CALL_PHONE}, 0);
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Handler handler = new Handler();
TelephonyManager.UssdResponseCallback responseCallback = 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_LONG).show();
}
@Override
public void onReceiveUssdResponseFailed(TelephonyManager telephonyManager, String request, int failureCode) {
super.onReceiveUssdResponseFailed(telephonyManager, request, failureCode);
Toast.makeText(MainActivity.this, "Failed " + request, Toast.LENGTH_LONG).show();
}
};
try {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
telephonyManager.sendUssdRequest("*#0011#", responseCallback, handler);
} catch (NullPointerException e){
e.printStackTrace();
}
}
}
答案 1 :(得分:0)
有一个很棒的服务叫做 AutoUssd (https://autoussd.com) 可以让你做到这一点。 (即从您的应用内拨打 USSD 代码)
SDK 允许您创建隐藏在布局文件后面的交互式多步骤 USSD 会话,会话结果通过回调报告给您的应用。
请检查它是否符合您的需求...