网页 调起 手机地图APP ,定位,识别等。。。。
2016-06-30 18:58
633 查看
最近需要弄一个需求功能,网页调用起手机的app地图定位,目前的地图软件比较大的如百度地图,高德地图
百度的官网参考api说明:http://developer.baidu.com/map/wiki/index.php?title=uri/api/android
高德的官网参考api说明:http://lbs.amap.com/api/uri-api/ios-uri-explain/
上面当中有IOS,Android指令之类的
如百度的android端调起:
注明参考:如果是自己开发的app,要调起,可以这么配置一下
参考自:
在Android本地app的配置
复制代码代码如下:
在AndroidManifest的清单文件里的intent-filte中加入如下元素:
<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="my.com"
android:scheme="m" />
</intent-filter>
接下来,进行步骤描述:
1.在asset目录下,新建一个map.html
2.使用webview加载即可
注意一点,加载的时候,不要设置这个
百度的官网参考api说明:http://developer.baidu.com/map/wiki/index.php?title=uri/api/android
高德的官网参考api说明:http://lbs.amap.com/api/uri-api/ios-uri-explain/
上面当中有IOS,Android指令之类的
如百度的android端调起:
bdapp://map/line?region=北京&name=518&src=yourCompanyName|yourAppName
注明参考:如果是自己开发的app,要调起,可以这么配置一下
参考自:
http://www.jb51.net/article/43928.htm
在Android本地app的配置
复制代码代码如下:
在AndroidManifest的清单文件里的intent-filte中加入如下元素:
<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="my.com"
android:scheme="m" />
</intent-filter>
接下来,进行步骤描述:
1.在asset目录下,新建一个map.html
<!DOCTYPE html> <!-- saved from url=(0051)http://developer.baidu.com/map/uri-introandroid.htm --> <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Android版百度地图调起说明</title> </head> <body> <br/> <br/> <a href="bdapp://map/line?region=北京&name=518&src=yourCompanyName|yourAppName">线路查询</a> </body> </html>
2.使用webview加载即可
注意一点,加载的时候,不要设置这个
webview.setWebViewClient(new MyWebViewClient(this,webview));
具体设置:参考附录加载webview java代码
参考自:http://blog.csdn.net/grp0916/article/details/51481330
然后就可以调起手机已经安装好的app
其中,要判断有没有存在这个app,判断用户是否安装了,可以这么做
private boolean isInstallPackage(String packageName) { return new File("/data/data/" + packageName).exists(); }
参考自 : http://www.jianshu.com/p/4597cfe21e5f
附录
加载webview java代码
package com.lvche.lvchedingdang.activity._360quan_jing.base; import android.annotation.TargetApi; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.KeyEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.webkit.WebSettings; import android.webkit.WebSettings.RenderPriority; import android.webkit.WebView; import com.lvche.lvcheappframelib.frame.common_utils.ActivityManage; import com.lvche.lvcheappframelib.frame.common_utils.LogUtils; import com.lvche.lvcheappframelib.frame.http_web_utils.MyWebChromeClient; import com.lvche.lvcheappframelib.frame.http_web_utils.MyWebViewClient; import com.lvche.lvchedingdang.R; import com.lvche.lvchedingdang.activity.BaseActivity; import com.lvche.lvchedingdang.application.MyApplication; import com.lvche.lvchedingdang.domain.JavascriptInterfaceFunction; import com.lvche.lvchedingdang.utils.http.HttpGetAndHttpPost; import com.lvche.lvchedingdang.views.webview.MyWebView; public class ModifyBaseActivity extends BaseActivity implements OnClickListener, OnPageChangeListener{ // 当前fragment的index protected int currentTabIndex; protected SharedPreferences userSettings = null; protected MyApplication application = null; protected WebSettings mWebSettings = null; protected WebView webview; /**oncreat页面已经加载过了url,onresume不需要重新加载*/ protected boolean isOncreateLoaded ; /**请求反问二级url 带过来的参数*/ protected String query = "''"; protected String path = null; /**和js交互的android端接口*/ protected static JavascriptInterfaceFunction js = null; protected boolean isLoad = true; protected ActivityManage activityManage = null; /** 未读消息数目线程*/ protected Thread unReadThread ; @TargetApi(Build.VERSION_CODES.JELLY_BEAN) protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @TargetApi(Build.VERSION_CODES.JELLY_BEAN) protected void init(String path) { activityManage = ActivityManage.getInstance(); activityManage.addActivity(this); initViews(); application = (MyApplication) getApplication(); js = new JavascriptInterfaceFunction(getApplicationContext(), webview, this, mWebSettings); webview.addJavascriptInterface(js,"androidNative"); isOncreateLoaded = true; webview.loadUrl(path); } /** * @Title: toGoBack * @Description: 点击左上角回退 返回 * @param @param view * @param @return 设定文件 * @return boolean 返回类型 * @throws */ public void toGoBack(View view) { this.finish(); } /** *返回键处理 */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { this.finish(); return true; } public void onPageScrollStateChanged(int arg0) { } public void onPageScrolled(int arg0, float arg1, int arg2) { } public void onPageSelected(int arg0) { } /** * @Title: initViews * @Description: TODO(实例化控件) * @return void 返回类型 * @throws */ protected void initViews() { // 实例化WebView对象 webview = (MyWebView) findViewById(R.id.pGGMall_mine_webview); // 设置WebView属性,能够执行Javascript脚本 webview.getSettings().setJavaScriptEnabled(true); mWebSettings = webview.getSettings(); /**webview 出现 nativeOnDraw failed; clearing to background color. 解决方法*/ ////webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); HttpGetAndHttpPost.webviewSetting(this, mWebSettings); /*取消缩放按钮zoom ,经常报错**/ mWebSettings.setBuiltInZoomControls(false); //webview.setWebViewClient(new MyWebViewClient(this,webview)); webview.setWebChromeClient(new MyWebChromeClient(webview,query)); /**关闭硬件加速问题 阻止nativeOnDraw failed; clearing to background color.出现*/ //webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null); /**告诉WebView先不要自动加载图片,等页面finish后再发起图片加载*/ if(Build.VERSION.SDK_INT >= 19) { webview.getSettings().setLoadsImagesAutomatically(true); } else { webview.getSettings().setLoadsImagesAutomatically(false); } /**不允许网页进行缩放*/ ////webview.getSettings().setBuiltInZoomControls(true); /**提高网页加速渲染的优先级*/ webview.getSettings().setRenderPriority(RenderPriority.HIGH); /**阻止加载图片*/ webview.getSettings().setBlockNetworkImage(true); } @Override public void finish() { try { activityManage.removeActivity(this); /**解决窗体溢出异常,就是finish之前,杀死所有view*/ ViewGroup view = (ViewGroup) getWindow().getDecorView(); view.removeAllViews(); //解决zoom缩放问题 webview.setVisibility(View.GONE); webview.removeAllViews(); webview.destroy(); } catch (Exception e) { LogUtils.e("关闭"+this.getClass().getName(), "出现异常"); } super.finish(); } @Override public void onClick(View v) { } }
具备参考价值的文章:
http://www.myexception.cn/operating-system/2078358.html
http://www.jb51.net/article/43928.htm
相关文章推荐
- Android 通过图片进行自定义View绘制
- iOS TheOperationCouldn'tbeCompleted
- [Objective-C]用Block实现链式编程
- unity, animtion倒放
- 自定义View,解决百分比布局适配时Textview的字体Textsize比例缩放问题
- 总结iOS App开发中控制屏幕旋转的几种方式
- Android 复习1 mvc设计模式
- Android 拍照以及一些常用的处理,例如将图片显示到相册(包含了安卓系统6.0以上调用相机的处理)
- 详解Swift中属性的声明与作用
- 在iOS开发中使用iconfont图标
- iOS下将照片保存到相册的三种方法
- Android 动态隐藏显示导航栏,状态栏
- Android获取手机的型号等
- “ java.lang.RuntimeException: Unable to instantiate application ”
- android 5.0之后如何获取当前运行的应用包名
- Android APP代码混淆proguard和加固
- android studio运行编译速度慢的解决方法
- NSArray分类
- android 腾讯微博
- 使用DialogFragment实现底部弹窗布局