对于activity,我们可以注册intent-filter声明自己对什么样的intent感兴趣,网页或其它App就能通过intent来打开我们的App并传递参数了,intent-filter里的action,category,data必须都匹配。

        <activity android:name=".TestActivity">            <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:scheme="testapp"                    android:host="testmodule"                    android:path="/showtitle"                    android:port="8000" />            intent-filter>        activity>

通过网页打开:

<html><head>    <title>testtitle>head><body>    <a href="testapp://testmodule:8000/showtitle?query1=1&title=hello">打开APPa>body><html>

通过其它App打开:

Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse("testapp://testmodule:8000/showtitle?query1=1&title=hello"));startActivity(intent);

在App中获取传递的参数:

public class TestActivity extends AppCompatActivity {    private static String TAG="TestActivity";    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_test);        Uri uri=getIntent().getData();        if (uri!=null){            String scheme=uri.getScheme();            String host=uri.getHost();            int port=uri.getPort();            String path=uri.getPath();            String query=uri.getQuery();            String title=uri.getQueryParameter("title");            Log.d(TAG,"scheme:"+scheme+",host:"+host+",port:"+port+",path:"+path+",query:"+query+",title:"+title);        }    }}
2019-09-06 12:01:17.220 6272-6272/com.xy.testapp D/TestActivity: scheme:testapp,host:testmodule,port:8000,path:/showtitle,query:query1=1&title=hello,title:hello

更多相关文章

  1. 一个Android菜鸟入门Flutter 笔记(一)
  2. Android异步任务简单使用
  3. android中menu.add()参数解析
  4. Android和H5交互
  5. android onCreate(Bundle savedInstanceState)
  6. Android中post请求传递json数据给服务端
  7. Android中实现长按照片弹出右键菜单
  8. Android复习之旅--Intent
  9. 手把手教你在Windows下搭建React Native Android开发环境

随机推荐

  1. Android中的getDimension,getDimensionPi
  2. Mac系统下,配置Android(安卓)gradle环境
  3. WebView的基本使用
  4. android项目解刨之时间轴
  5. 单例模式在android中的应用
  6. Android(安卓)Studio - no debuggable ap
  7. ContentProvider基本使用
  8. Android(安卓)APP LOGO尺寸
  9. android Listview 软引用SoftReference异
  10. android布局文件中一些属性介绍