拦截ussd消息android应用程序 [英] Intercept ussd message android application

查看:76
本文介绍了拦截ussd消息android应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



大家好,我最近被分配到一个新的Android项目,这是一个具有挑战性的项目,我喜欢它,这里是我面临的问题很重要。



我需要拦截一条ussd消息,我试图通过调查,但我没有发现真的可以提供帮助。



请指出我可以开始的任何事情。



很多谢谢



我的尝试:



protected void call(String phoneNumber){

尝试{

startActivityForResult(

new Intent(android.intent.action.CALL,Uri.parse(phoneNumber)),1);

} catch(Exception eExcept){

String msg = eExcept.toString();



this.view.append( \ n \\ n+\ n+ msg);

}

}










公共类MyService扩展AccessibilityService {

public static String TAG = MyService.class.getSimpleName();



@Override

public void onAccessibilityEvent(AccessibilityEvent事件){

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是标准但不适用于所有手机* /

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))){

返回;

}

if(event.getEventType()== AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED&& TextUtils.isEmpty(source.getText ())){

返回;

}



列表< 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;



//关闭对话框

performGlobalAction(GLOBAL_ACTION_BACK); //仅适用于4.1+



Log.d(TAG,text);

//在此处理USSD响应



}



private String processUSSDText(List< charsequence> eventText){

for (CharSequence s:eventText){

String text = String.valueOf(s);

//如果文本是预期的ussd响应,则返回文本

if(true){

返回文字;

}

}

返回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);

}

}

解决方案

ussd messages android - Google搜索 [ ^ ]。

Hi everybody,

Hello guys, I have recently assigned to work on a new Android project, it is a challenging one, and I liked it, here is the problem matter I faced.

I need to intercept a ussd message, I have tried to investigate through but I didn't find that really can help.

Please indicate me anything that I can start with.

Lot's of Thanks

What I have tried:

protected void call(String phoneNumber) {
try {
startActivityForResult(
new Intent("android.intent.action.CALL", Uri.parse(phoneNumber)), 1);
} catch (Exception eExcept) {
String msg = eExcept.toString();

this.view.append("\n\n " + "\n" + msg);
}
}





public class MyService extends AccessibilityService {
public static String TAG = MyService.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);
}
}

解决方案

ussd messages android - Google Search[^].


这篇关于拦截ussd消息android应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆