Starting an ACTION_VIEW activity to open the browser, how do I return to my app?

The Application cannot find out if user has finished with ban page or not. usually bank payment gateways called with a callBackUrl attribute.

i handle this situation like this:

  1. on my callBackUrl i set a url to verify payment page (Web page page)
  2. in verify payment page`s html, i made a button labeled as "Return To Application" this Button href is a url like this "/app/order/payed"
  3. in my Android application i make use of Android App Link

Html Page:

<div class="flex-center position-ref" style='height:30vh;'>
          <a href="http://myserver/app/order/payed" class="btn-success">
            Return To Application
          </a>
        </div>

in Android Manifest:

<activity
            android:name=".shop.customer.order.OrderPayedActivity"
            android:launchMode="singleInstance"
            android:taskAffinity=".shop.customer.cart.CartActivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="@string/BASE_URL_HOST"
                    android:pathPattern="/app/order/payed"
                    android:scheme="@string/BASE_URL_SCHEME" />
            </intent-filter>
        </activity>

and in The Receiving Activity:

//managed parent activities in the manifest in order to make task`s back stack 
 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = new Intent(this,OrderListActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

    TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this);
    taskStackBuilder.addNextIntentWithParentStack(intent);

    taskStackBuilder.startActivities();
    //startActivity(intent);
    finish();
}

Actually you are able to return to your calling activity taking a different approach. If the webpage you are calling is handled by you or allows you to assign a callback when the user finishes doing dome processing, then you can set that callback to a URI, and assign that URI to your calling activity, if the activity launch mode is singleTask, then you're going to be able to resume your activity.

The only thing that I haven't resolved is that I don't know how to remove the browser from the stack once it returns to your calling activity. I want to accomplish this because once you leave your app, android pops the browser activity to the front, forcing the user to finish it by himself.


How would the browser know that user is done with the bank page? It has no way to know that.

Also, browser does not react to startActivityForResult() by setting result and then finish().

So, you can not use Android browser to accomplish this task.

The only possible way would be to start WebView and to detect when user is finished, by detecting certain url that is (supposedly) shown when user is finished with the bank task.

Tags:

Android