1、在待打开的APP注册可被外APP调用的activity
<activity android:name=".TwoActivity">
<intent-filter >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="test"
android:host="com.example.mvvmtest"
android:path="/home" />
</intent-filter>
</activity>
注:host是包名
2、任意APP打开已注册的开放的activity
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("test://com.example.mvvmtest/home"));
intent.putExtra("name","aacc44");
startActivity(intent);
<intent-filter> <category android:name="android.intent.category.DEFAULT"/> <action android:name="android.intent.action.VIEW"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="dogness" android:host="rice" android:path="/device" /> </intent-filter>
dongness://rice/device
dongness://rice/device?sn=365622952860844032
Uri uri = getIntent().getData(); if (uri !=null){ xiexunss = uri.getQueryParameter("dognesscode"); LgqLogPlus.d("浏览器返回==== "+xiexunss); SharedPreUtil.putString("liulanqidp",xiexunss); }
/** * 跳转至商品详情 * * @param activity Activity * @param url 商品详情 */ fun gotoGoodsDetail(activity: Activity, url: String?) { try { //测试商品url val intent = Intent() intent.action = "Android.intent.action.VIEW" val uri = Uri.parse(url) // 商品地址 intent.data = uri intent.setClassName( "com.taobao.taobao", "com.taobao.tao.detail.activity.DetailActivity" ) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK activity.startActivity(intent) } catch (e: Exception) { e.printStackTrace() } }
/** * 跳转京东详情页 */ public void openJD2(String id) { if (checkPackage("com.jingdong.app.mall")) { // String url = "https://item.jd.com/231023.html";//这是京东商品详情页 // String id = "100038821904";//需要提取商品id,添加到下面url,不能单独将商品详情页作为url传入 String url = "openapp.jdmobile://virtual?params=%7B%22sourceValue%22:%220_productDetail_97%22,%22des%22:%22productDetail%22,%22skuId%22:%22"+id+"%22,%22category%22:%22jump%22,%22sourceType%22:%22PCUBE_CHANNEL%22%7D"; Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); Uri uri = Uri.parse(url); intent.setData(uri); // intent.setClassName("com.jingdong.app.mall","com.jd.lib.productdetail.ProductDetailActivity");//不需要 startActivity(intent); } }
if (appChannel!=null&&appChannel.equals("JD")){ if (checkPackage("com.jingdong.app.mall")) { openJD2("100038821904"); // openJD2(url); return; } } if (appChannel!=null&&appChannel.equals("TMAO")){ if (checkPackage("com.tmall.wireless")) { gotoShop(getActivity(), url); // gotoShop(getActivity(), "tmall://page.tm/shop?shopId=185441148"); return; } } if (appChannel!=null&&appChannel.equals("TBAO")){ if (checkPackage("com.taobao.taobao")) { gotoShop(getActivity(), url); // gotoShop(getActivity(), "taobao://shop.m.taobao.com/shop/shop_index.htm?shop_id=185441148"); return; } } if (appChannel!=null&&appChannel.equals("PDD")){ if (checkPackage("com.xunmeng.pinduoduo")) { // String content = "pinduoduo://com.xunmeng.pinduoduo/duo_coupon_landing.html?goods_id=329990619550"; String content = url; Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(content)); startActivity(intent); return; } }
/** * 跳转至商铺 * * @param activity Activity * @param url 商铺地址 */ public static void gotoShop(Activity activity, String url) { try { Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); intent.setData(Uri.parse(url)); activity.startActivity(intent); } catch (Exception e) { e.printStackTrace(); } }
/** * 检测该包名所对应的应用是否存在 ** @param packageName * @return */ public boolean checkPackage(String packageName) { if (packageName == null || "".equals(packageName)) return false; try { //手机已安装,返回true mContext.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); return true; } catch (PackageManager.NameNotFoundException e) { //手机未安装,跳转到应用商店下载,并返回false Uri uri = Uri.parse("market://details?id="+packageName); Intent it = new Intent(Intent.ACTION_VIEW, uri); startActivity(it); return false; } }