Click here to Skip to main content
15,890,995 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
}
}
Posted
Updated 22-Feb-17 0:37am
Comments
Richard MacCutchan 22-Feb-17 4:21am    
"Please indicate me anything that I can start with."

You could tell us what the problem is.
Yonathan1111 22-Feb-17 6:07am    
steps or algorithms that I can adapt so that I can intercept ussd messages, the whole purpose of the project is to read ussd response.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900