How to close/cancel/dismiss a System Dialog programmatically (Android)

后端 未结 3 922
别那么骄傲
别那么骄傲 2020-12-31 14:16

I have an app that make USSD calls, but after all USSD calls i got a dialog with the result to the user.

I know that is possible to dismiss this dialog because the \

相关标签:
3条回答
  • 2020-12-31 14:59

    Just add this line in your code.

    Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
    sendBroadcast(intent);
    
    0 讨论(0)
  • 2020-12-31 15:11

    I have found a simple answer from this blog here. First we have to create a simple Accessibility service.The Accessibility Service works only if it's enable.In setting there is a option Accessibility,in that turn on your project and give permission to your service class.

    Note: Method performGlobalAction (GLOBAL_ACTION_BACK) requires Android 4.1+, if it is not used, it is possible to meet the 4.0. It closes the window immediately after the AlertDialog,

    here the sample code:

     public class USSDService extends AccessibilityService {
     String TAG="USSDService";
        @Override
        public void onAccessibilityEvent(AccessibilityEvent event) {
       //In my mobile the class name has been looks like this.
            if (event.getClassName().equals("com.mediatek.phone.UssdAlertActivity")) {
     //Method performGlobalAction (GLOBAL_ACTION_BACK) requires Android     
      //  4.1+
                performGlobalAction(GLOBAL_ACTION_BACK);
            }
        }
    
        @Override
        public void onInterrupt() {
    
    
        }
    @Override
    protected void onServiceConnected() {
        super.onServiceConnected();
          Log.v(TAG, "onServiceConnected");
            AccessibilityServiceInfo info = new AccessibilityServiceInfo();
            info.flags = AccessibilityServiceInfo.DEFAULT;
            info.packageNames = new String[]
                    {"com.android.phone"};
            info.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
            info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
            setServiceInfo(info);
     }
    
    }
    

    In Manifest add the following things:

    <service 
      android:name=".USSDService"
      android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" >
    <intent-filter>
    <action android:name="android.accessibilityservice.AccessibilityService" />
    </intent-filter>
    

    0 讨论(0)
  • 2020-12-31 15:16

    I found an Answer to my question if you're trying to use USSD Calls you can disable the result text

    In a russian blog there is a post that show how you can connect to the phoneutils service of android, then control the texts from USSD (CALL and RESULT). He show a sample using a interface (IExtentedendNetworkService ) that binds on phone utils just on the android OS start and if there was not any other app trying to do the same (Because just one service can be bound and maybe will be your or not, I don't know the rule that Android OS uses to choose).

    In the function "CharSequence getUserMessage(CharSequence text);" if you return null the result dialog will not appear.

    0 讨论(0)
提交回复
热议问题