Hide Android Dialog of the USSD call

0

Currently I have an application where I am making USSD calls, which generates a dialog window of the system's own type showing the options,

What I would like is to hide it, eliminate it

    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>

Also try to perform

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        this.keepFocus = true;
    }

    if (! hasFocus && this.keepFocus) {
        ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
        am.moveTaskToFront(getTaskId(), ActivityManager.MOVE_TASK_WITH_HOME );
    }
}

all failed attempts

my class where I invoke the USSD call is the following

    public class Login extends AppCompatActivity {


    private final static int MY_PERMISSIONS_REQUEST_CALL_PHONE = 123;
    private boolean keepFocus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

    }

    /*
     Metodo para iniciar seccion en la aplicacion
    */
    public void GoToLogin(View view) {
/*
        TextView txtPass = (TextView) findViewById(R.id.txtPasswordLogin);
        String pass = txtPass.getText().toString();
        if (pass.length() == 0) {
            Toast.makeText(this, "Debe ingresar la contraseña ", Toast.LENGTH_LONG).show();
        }
        if (pass.length() > 0) {
            Intent intent = new Intent(this, UpdateSecretQuestions.class);
            startActivity(intent);
        }
*/


        String USSD = Uri.encode("*") + "611" + Uri.encode("#");
        requestUSSD(USSD);

        Globals.getTEXT();
        Globals.getTEXT();
    }

    private void dailNumber(String s) {
        String USSD = Uri.encode("*") + "611" + Uri.encode("#");
        startActivity(new Intent("android.intent.action.CALL", Uri.parse("tel:" + USSD)));
    }


    private void requestUSSD(String USSD){

        if (ActivityCompat.checkSelfPermission(Login.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, MY_PERMISSIONS_REQUEST_CALL_PHONE);
            return;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { //API >= 26
            TelephonyManager manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
            manager.sendUssdRequest(USSD, new TelephonyManager.UssdResponseCallback() {
                @Override
                public void onReceiveUssdResponse(TelephonyManager telephonyManager, String request, CharSequence response) {
                    super.onReceiveUssdResponse(telephonyManager, request, response);
                    Toast.makeText(getApplicationContext(), "onReceiveUssdResponse()" + response, Toast.LENGTH_LONG).show();
                }
                @Override
                public void onReceiveUssdResponseFailed(TelephonyManager telephonyManager, String request, int failureCode) {
                    super.onReceiveUssdResponseFailed(telephonyManager, request, failureCode);
                    Toast.makeText(getApplicationContext(), "onReceiveUssdResponseFailed()" + request, Toast.LENGTH_LONG).show();
                }
            }, new Handler());
        }else{      //API < 26
            startService(new Intent(this, XXXX.class));
            dailNumber("*611#");
        }

    }
    //Detecta si los permisos fueron concedidos (android 6.0+)
    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        switch (requestCode) {
            case MY_PERMISSIONS_REQUEST_CALL_PHONE : {
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // PERMISO CONCEDIDO!
                } else {
                    Toast.makeText(getApplicationContext(), "No se tienen permisos CALL_PHONE!", Toast.LENGTH_LONG).show();
                }
                return;
            }
        }
    }



}

any help on how to hide the dialogue of the USSD call, or how to hide the poputs of the android system, thanks

    
asked by Bruno Sosa Fast Tag 25.10.2017 в 22:31
source

0 answers