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

前端 未结 4 906
终归单人心
终归单人心 2021-01-11 11:43

In my app i need to open the bank\'s page, to make the user able to pay. Reading the Android documentation I see that I should use an ACTION_VIEW (and not a Web

相关标签:
4条回答
  • 2021-01-11 12:10

    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();
    }
    
    0 讨论(0)
  • 2021-01-11 12:17

    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.

    0 讨论(0)
  • 2021-01-11 12:21

    Just put a ResultCode argument on your startActivityForResult method, something like =this.startActivityForResult(intent, PAYMENT_ACCEPTED)

    It will be returned as resultCode when you finish your second activity.

    0 讨论(0)
  • 2021-01-11 12:24

    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.

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