在Android应用中付款后如何重定向到外部链接?

时间:2018-08-25 09:27:36

标签: android redirect

我已经创建了自己的android应用程序,现在卡住了,在android应用程序中完成付款后,如何将用户重定向到外部链接?

我已使用AIDL应用内结算,所以这里可以发布任何示例代码,用我的外部链接替换吗?

我是编码方面的新手。所以我没有做太多尝试。

2 个答案:

答案 0 :(得分:0)

这是一个示例:

    Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
    startActivity(intent);

您可以在:

中阅读更多内容

https://developer.android.com/reference/android/content/Intent

您可以创建一个方法:

public void newActivity(String uri){
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        startActivity(intent);

    }

调用方法:

newActivity("https://www.google.com");
newActivity("https://www.youtube.com");
newActivity("https://www.iosdroid.es");

答案 1 :(得分:0)

如果您检出developers page about this,则会发现:

  

c。结帐流程完成后(即用户成功购买了商品或取消了购买),Google Play会向您的onActivityResult方法发送响应意图。 onActivityResult的结果代码具有指示购买成功还是被取消的结果代码

因此,要在活动中获得这种意图是第一步:

@Override
public void onActivityResult(int 
requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, 
resultCode, data);
    if (resultCode == RESULT_OK) {
       //redirect to the new page
    }
}

重定向到新页面很容易:

String url = "http://www.example.com";//here goes your url
Intent i = new 
Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i); //this starts it in the browser

Here,您有一个很好的完整教程!

如果您有多个产品,并且每个产品的网址不同,则可以检查活动中所购买的产品, 数据包。