几天来,我一直在这里和其他论坛上阅读有关USSD对话的线索.(USSD表示运营商的通知,其中包含通话费用详情).
我已经看到很多解决方案显然适用于Android中较低的API级别,但经过大量的测试,认为它们不再工作或者至少我无法让它们工作.
首先,我想知道是否有任何方法可以检测是否已向用户显示ussd对话框.所以我试过这个: 阻止USSD对话并阅读USSD回复?
但我从日志中获得的所有东西都与我的应用程序有关,虽然我可以在Eclipse的LogCat中看到它们,但我的应用程序中没有捕获到MMI相关的日志!也许它的工作版本低于我的Android版本(4.2.2).
然后我决定使用"IExtendedNetworkService",就像它在以下链接中使用的那样:
https://github.com/alaasalman/ussdinterceptor
使用IExtendedNetworkService在Android中获取USSD响应
实施USSD功能.将服务绑定到PhoneUtils,而不是在每次更新时重新启动手机
但它对Android 4.2.2及更高版本也没用.
然后我找到了这个链接: 如何解除Android中的系统对话框?
它似乎很有希望,但即使经过大量的测试,我也无法使它工作.我想也许我做错了什么,或者也是为了降低API.
之后我尝试了许多其他的东西,比如模拟主键和后退键,甚至以编程方式触摸隐藏该通知,但由于它们都在我自己的活动下工作,所以没有一个工作.
有谁知道这些方法或其他方法是否适用于管理甚至检测Android 4.2.2及更高版本中的USSD消息?
我非常感谢任何帮助,提前谢谢.
可以使用辅助功能服务.首先创建一个服务类:
public class USSDService extends AccessibilityService {
public static String TAG = USSDService.class.getSimpleName();
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
Log.d(TAG, "onAccessibilityEvent");
AccessibilityNodeInfo source = event.getSource();
/* if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && !event.getClassName().equals("android.app.AlertDialog")) { // android.app.AlertDialog is the standard but not for all phones */
if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED && !String.valueOf(event.getClassName()).contains("AlertDialog")) {
return;
}
if(event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED && (source == null || !source.getClassName().equals("android.widget.TextView"))) {
return;
}
if(event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED && TextUtils.isEmpty(source.getText())) {
return;
}
List<CharSequence> eventText;
if(event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
eventText = event.getText();
} else {
eventText = Collections.singletonList(source.getText());
}
String text = processUSSDText(eventText);
if( TextUtils.isEmpty(text) ) return;
// Close dialog
performGlobalAction(GLOBAL_ACTION_BACK); // This works on 4.1+ only
Log.d(TAG, text);
// Handle USSD response here
}
private String processUSSDText(List<CharSequence> eventText) {
for (CharSequence s : eventText) {
String text = String.valueOf(s);
// Return text if text is the expected ussd response
if( true ) {
return text;
}
}
return null;
}
@Override
public void onInterrupt() {
}
@Override
protected void onServiceConnected() {
super.onServiceConnected();
Log.d(TAG, "onServiceConnected");
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.flags = AccessibilityServiceInfo.DEFAULT;
info.packageNames = new String[]{"com.android.phone"};
info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED | AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
setServiceInfo(info);
}
}
Run Code Online (Sandbox Code Playgroud)
在Android清单中声明它
<service android:name=".USSDService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data android:name="android.accessibilityservice"
android:resource="@xml/ussd_service" />
Run Code Online (Sandbox Code Playgroud)
创建一个描述名为ussd_service的辅助功能服务的xml文件
<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeWindowStateChanged|typeWindowContentChanged"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagDefault"
android:canRetrieveWindowContent="true"
android:description="@string/accessibility_service_description"
android:notificationTimeout="0"
android:packageNames="com.android.phone" />
Run Code Online (Sandbox Code Playgroud)
而已.安装应用程序后,您必须在"辅助功能设置"(设置 - >辅助功能设置 - > YourAppName)中启用该服务.
小智 0
不幸的是没有办法。
我们一直在寻找该命令也是解决这个问题的方法,但如果结果是仅通过解析手机中的日志来获取信息,并不能保证在所有设备上 100% 的工作。
结果我们和国内的移动运营商达成协议(我们只有3家移动运营商),他们给我们提供了获取电话号码余额的API,但是这个方法只在本地有效。
归档时间: |
|
查看次数: |
8428 次 |
最近记录: |