查找资料:
http://www.apkbus.com/android-173528-1-1.html
根据这篇文章的介绍,同样也是在找如何从自己写的APP,跳转到原生淘宝APP。里面的思路是通过Intent 隐式跳转到淘宝原生APP上面。但是intent隐式跳转你得知道淘宝App的包名,所以就得去反编译。结果下载下来淘宝APP,反编译就是不成功。 结果就找到了一个好的源码网站:
http://www.cntofu.com/com.taobao.taobao/AndroidManifest.xml
找到了淘宝APP的包名,就可以做隐式跳转了。首先找到manifest.xml 文件的所要跳转到的界面。 源码如下
<activity android:theme="@style/Theme.NoBackgroundAndTitle" android:name="com.taobao.tao.shop.ShopActivity" android:launchmode="singleTop" android:screenorientation="portrait" android:configchanges="keyboardHidden|orientation" android:windowsoftinputmode="adjustPan">
<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="http" android:host="shop.m.taobao.com" android:path="/shop/shop_index.htm">
<data android:path="/shop/shop_info.htm">
<data android:scheme="taobao">
<data android:scheme="itaobao">
</data></data></data></data></category></action></category></intent-filter>
<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="http" android:host="store.taobao.com" android:path="/shopiewShop.htm">
</data></category></action></category></intent-filter>
<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="http" android:host="h5.m.taobao.com" android:path="/awp/core/shop.htm">
<data android:scheme="taobao">
</data></data></category></action></category></intent-filter>
</activity>
然后就可以根据自己的店铺地址 ,在java文件中Intent 跳转了
if(url.contains("taobao://")){
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri uri = Uri.parse(url);
intent.setData(uri);
startActivity(intent);
}else{
view.loadUrl(url);
}
问题出现了,当手机没安装淘宝APP的时候就会报错,出现问题:所以需要一种更完善的方案:
1、创建一个启动淘宝客户端的intent
2、通过PackageManager查询能处理该intent的应用
3、如果有,则startActivity,否则启动Web
PS.可以参考下新浪微博第三方账号授权的实现方式
/**
* 检测该包名所对应的应用是否存在
* @param packageName
* @return
*/
public boolean checkPackage(String packageName)
{
if (packageName == null || "".equals(packageName))
return false;
try
{
mContext.getPackageManager().getApplicationInfo(packageName, PackageManager
.GET_UNINSTALLED_PACKAGES);
return true;
}
catch (PackageManager.NameNotFoundException e)
{
return false;
}
}
————————————————————————————————————————————————————————————————————————————
在webview中跳转出现一种情况
Getting net::ERR_UNKNOWN_URL_SCHEME while calling telephone number from HTML page in Android
解决方案:
http://blog.csdn.net/jdsjlzx/article/details/47727719
http://www.zhihu.com/question/20948215
对淘宝自身设计的协议不处理:
else if(url.contains("taobao://")){
}
最后加一个判断得以完善此过程
if(checkPackage("com.taobao.taobao")){
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
String url = "taobao://shop.m.taobao.com/shop/shop_index.htm?shop_id=131259851&spm=a230r.7195193.1997079397.8.Pp3ZMM&point" +
"=%7B%22from%22%3A%22h5%22%2C%22url%22%3A%22http%3A%2F%2Fshop131259851.m.taobao.com%2F%22%2C%22h5_uid%22%3A%22aJHIDr" +
"hLh0cCAYYbRtrrS3Ut%22%2C%22uaPoint%22%3A%22Mozilla%2F5.0%2520(Linux%3B%2520Android%25205.0.1%3B%2520SM-N9109W%2520Bui" +
"ld%2FLRX22C%3B%2520wv)%2520AppleWebKit%2F537.36%2520(KHTML%2C%2520like%2520Gecko)%2520Version%2F4.0%2520Chrome%2F43" +
".0.2357.121%2520Mobile%2520Safari%2F537.36%2520Rong%2F2.0%22%7D";
Uri uri = Uri.parse(url);
intent.setData(uri);
startActivity(intent);
}else{
Intent intent = new Intent(mContext, WebViewUI.class);
intent.putExtra(WebViewUI.KEY_LOAD_URL, "https://shop131259851.taobao.com/?spm=a230r.7195193.1997079397.8.Pp3ZMM");
intent.putExtra(WebViewUI.KEY_CONTENT_NAME, "四眼蜗牛");
startActivity(intent);
}