Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. public class USSDService extends AccessibilityService {
  2. public static String TAG = "USSDService";
  3. public String responsee="";
  4. @Override
  5. public void onAccessibilityEvent(AccessibilityEvent event) {
  6. Log.d(TAG, "onAccessibilityEvent");
  7. String text = event.getText().toString();
  8.  
  9. if (event.getClassName().equals("android.app.AlertDialog")) {
  10. performGlobalAction(GLOBAL_ACTION_BACK);
  11. Log.d(TAG, text);
  12. Intent intent = new Intent("message");
  13. intent.putExtra("value", text);
  14. Toast.makeText (this,text,Toast.LENGTH_LONG).show();
  15.  
  16. this.sendBroadcast(intent);// write a broad cast receiver and call sendbroadcast() from here, if you want to parse the message for balance, date
  17. }
  18.  
  19. }
  20.  
  21. @Override
  22. public void onInterrupt() {
  23. }
  24.  
  25. @Override
  26. protected void onServiceConnected() {
  27. super.onServiceConnected();
  28. Log.d(TAG, "onServiceConnected");
  29. AccessibilityServiceInfo info = new AccessibilityServiceInfo();
  30. info.flags = AccessibilityServiceInfo.DEFAULT;
  31. info.packageNames = new String[]{"com.android.phone"};
  32. info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
  33. info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
  34. setServiceInfo(info);
  35. }}
  36.  
  37. public class MainActivity extends AppCompatActivity {
  38.  
  39. private BroadcastReceiver bReceiver = new BroadcastReceiver(){
  40.  
  41. @Override
  42. public void onReceive(Context context, Intent intent) {
  43. //put here whaterver you want your activity to do with the intent received
  44. Log.i("onReceive",intent.getStringExtra("value") );
  45. }
  46. };
  47.  
  48. protected void onResume(){
  49. super.onResume();
  50. Log.i("onResume", "22222");
  51. LocalBroadcastManager.getInstance(this).registerReceiver(bReceiver, new IntentFilter("message"));
  52. }
  53.  
  54. protected void onPause (){
  55. super.onPause();
  56. Log.i("onPause", "11111");
  57.  
  58. LocalBroadcastManager.getInstance(this).unregisterReceiver(bReceiver);
  59. }
  60. @Override
  61. protected void onCreate(Bundle savedInstanceState) {
  62.  
  63. super.onCreate(savedInstanceState);
  64. setContentView(R.layout.activity_main);}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement