Android开发之--从app中跳转到淘宝店铺

首先、一个工具类   方法,检测该包名下的应用是否存在

public static boolean checkPackage(Context context ,String packageName)
{
    if (packageName == null || "".equals(packageName))
        return false;
    try{
        context.getPackageManager().getApplicationInfo(packageName, PackageManager
                .GET_UNINSTALLED_PACKAGES);
        return true;
    }catch (PackageManager.NameNotFoundException e){
        return false;
    }

}

然后就是在需要的地方调用

以下是打开淘宝的方法 

调用工具类,判断该包名下的应用是否存在,如果存在,则跳转,如果不存在,则打开网页版默认地址

 private void openTaobaoShopping() {
        if (DeviceUtil.checkPackage(this, "com.taobao.taobao")) {
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
//            https://detail.tmall.com/item.htm?id=535823983028&spm=a21bo.7932663.item.2.0mvUrk&scm=1007.13596.65361.100200300000014
            String url = "taobao://shop.m.taobao.com/shop/shop_index.htm?shop_id=131259851&spm=a230r.7195193.1997079397.8.Pp3ZMM&point";
            Uri uri = Uri.parse(url);
            intent.setData(uri);
            startActivity(intent);
        } else {
            WebViewActivity.open(MainActivity.this, "https://shop131259851.taobao.com/?spm=a230r.7195193.1997079397.8.Pp3ZMM");
        }
    }


接下来 是WebViewActivity中的open方法  它是打开网页版路径:

public static void open(Context context,String url){
    Intent intent = new Intent();
    intent.setClass(context,WebViewActivity.class);
    intent.putExtra("webUrl",url);
    context.startActivity(intent);
}

其中 webviewactivity中 布局只是一个webview

<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fadingEdge="none"
    android:visibility="invisible"
    android:fadingEdgeLength="0dp"
    android:scrollbars="none" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值