0

I have a webview that loads particular website on it the user has to do a validation that can only be done by the browser, the user clicks on the link and opens the android browser and does this validation, it is possible to create a back button for the application at the top of the browser because after the validation the user has no way to go back to the application, on the iphone there is the navigation controller and when the user clicks on a link that opens browser is created a back button on top of the mobile is possible on android?

denis
  • 129
  • 1
  • 6

1 Answers1

0

Not directly.

There are two ways I see you could work with this limitation.

  1. Make a toast to tell the user to come back to your application.
  2. Use a touchable overlay and add it to the display when the user performs the action that directs them to the browser. When that overlay is tapped, have your application "relaunch."

You can make a simple clickable overlay like this:

ImageView button = new ImageView(context); //this can be any View you want, even your own custom subclass
button.setImageResource(R.drawable.back); 
button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        //handle relaunching your app here
    }
})

WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.height = 50; //height and width are in pixels
params.width = 50;
params.type = Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1 ? 
                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY : 
                WindowManager.LayoutParams.TYPE_PHONE;
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
params.gravity = Gravity.TOP | Gravity.START;

WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
manager.addView(button, params); //add the button to the screen

manager.removeView(button); //remove the button from the screen

You'll need the SYSTEM_ALERT_WINDOW_PERMISSION for this: How to handle SYSTEM_ALERT_WINDOW permission not being auto-granted on some pre-Marshmallow devices

To handle relaunching your app, add launchMode="singleInstance" to your Activity tag in your AndroidManifest and then simply use startActivity() on it from inside the onClick() method.

TheWanderer
  • 16,775
  • 6
  • 49
  • 63