浏览器打开android应用APP
2015-11-09 23:47
323 查看
浏览器打开android系统的应用使用的是隐式的Intent进行设置的,隐式的Intent可以比显示的Intent的优势很大,不仅可以跨应用调APP,还可以通过浏览器打开本地的APP,下面我们看如何进行设置的。
首先建立一个android应用,创建一个Activity和布局:
LauchLocalActivity:
修改如下:
到此android已经完成了,下面我们写一个简单的html页面来启动我们的APP:
要使用android系统上面的浏览器访问(务必谨记:android系统上面的localhost我们换成10.0.2.2才可以进行访问端口还是自己设置的端口默认80)
![](http://img.blog.csdn.net/20151109234522899?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
点击启动之后的效果:
![](http://img.blog.csdn.net/20151109234550932?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
我们传递的参数也获取到了。至此,浏览器启动androidAPP应用完毕,希望可以帮助大家。
首先建立一个android应用,创建一个Activity和布局:
LauchLocalActivity:
package com.example.firstday; import android.app.Activity; import android.net.Uri; import android.os.Bundle; import android.widget.EditText; public class LauchLocalActivity extends Activity { private EditText editText2,editText1; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_local); //获取浏览器传递的参数 Uri uri = getIntent().getData(); System.out.println(uri); String name = uri.getQueryParameter("name"); String content = uri.getQueryParameter("content"); editText2 = (EditText) findViewById(R.id.editText2); editText1 = (EditText) findViewById(R.id.editText1); editText1.setText(name); editText2.setText(content); } }布局文件activity_local.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我是通过浏览器启动的" /> <EditText android:id="@+id/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" /> <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textMultiLine" /> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="提交" /> </LinearLayout>找到AndroidManifest.xml文件
修改如下:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.firstday" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- 配置通过浏览器访问打开应用配置 --> <activity android:name=".LauchLocalActivity" android:label="@string/local"> <intent-filter> <category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.DEFAULT" /> <action android:name="android.intent.action.VIEW"/> <data android:scheme="local" android:host="first.app" android:pathPrefix="/first"/> </intent-filter> </activity> </application> </manifest>
到此android已经完成了,下面我们写一个简单的html页面来启动我们的APP:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <a href="local://first.app/first?name=gaoxuxu&content=分享的第一个浏览器打开的应用">启动一个APP应用</a> </body> </html>
要使用android系统上面的浏览器访问(务必谨记:android系统上面的localhost我们换成10.0.2.2才可以进行访问端口还是自己设置的端口默认80)
点击启动之后的效果:
我们传递的参数也获取到了。至此,浏览器启动androidAPP应用完毕,希望可以帮助大家。
相关文章推荐
- iOS开发-归纳总结(上)
- iOS程序破解——ARM汇编基础
- android界面之间数据的传递
- Objective-C 中 +load 与 +initialize
- iOS 第三课 九宫格建立 封装以及mvc的初步理解
- Objective-C @encode关键字
- Android:shape的使用详解(1)
- iOS中block的探究
- android 群英传笔记----Android scroll
- Android的ContentObserver类,实现监听手机短信
- IOS 调整内存中的图片大小
- iOS GCD
- IOS 自定义控件之-显示下载过程的ImageView
- Js中apply和call
- Linq to object
- 【cocos2d-js】创建单一颜色的精灵
- iOS——oc——多态
- LinearLayout布局的layout_weight属性
- Android进阶之路——Android Studio使用与5.0新特性
- IOS 七种手势详解(动图+Demo下载)