• android intent.setData intent.setDataAndType


    androidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest
        xmlns:android="http://schemas.android.com/apk/res/android"
        package="org.crazyit.intent"
        android:versionCode="1"
        android:versionName="1.0">
        <uses-sdk
            android:minSdkVersion="10"
            android:targetSdkVersion="15" />
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name">
            <activity
                android:name=".DataTypeAttr"
                android:label="@string/title_activity_data_type_attr">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:icon="@drawable/ic_scheme"
                android:name=".SchemeActivity"
                android:label="指定scheme的Activity">
                <intent-filter>
                    <action android:name="xx" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <!-- 只要Intent的Data属性的scheme是lee即可启动该Activity -->
                    <data android:scheme="lee" />
                </intent-filter>
            </activity>
            <activity
                android:icon="@drawable/ic_host"
                android:name=".SchemeHostPortActivity"
                android:label="指定scheme、host、port的Activity">
                <intent-filter>
                    <action android:name="xx" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <!-- 只要Intent的Data属性的scheme是lee、且host是www.fkjava.org
                    、port是8888即可启动该Activity -->
                    <data
                        android:scheme="lee"
                        android:host="www.fkjava.org"
                        android:port="8888" />
                </intent-filter>
            </activity>
            <activity
                android:icon="@drawable/ic_sp"
                android:name=".SchemeHostPathActivity"
                android:label="指定scheme、host、path的Activity">
                <intent-filter>
                    <action android:name="xx" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <!-- 只要Intent的Data属性的scheme是lee、且host是www.fkjava.org
                    、path是/mypath即可启动该Activity -->
                    <data
                        android:scheme="lee"
                        android:host="www.fkjava.org"
                        android:path="/mypath" />
                </intent-filter>
            </activity>    
            <activity
                android:icon="@drawable/ic_path"
                android:name=".SchemeHostPortPathActivity"
                android:label="指定scheme、host、port、path的Activity">
                <intent-filter>
                    <action android:name="xx" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <!-- 需要Intent的Data属性的scheme是lee、且host是www.fkjava.org
                    、port是8888、且path是/mypath才可启动该Activity -->
                    <data
                        android:scheme="lee"
                        android:host="www.fkjava.org"
                        android:port="8888"
                        android:path="/mypath"/>
                </intent-filter>
            </activity>
            <activity
                android:icon="@drawable/ic_type"
                android:name=".SchemeHostPortPathTypeActivity"
                android:label="指定scheme、host、port、path、type的Activity">
                <intent-filter>
                    <action android:name="xx"/>
                    <category android:name="android.intent.category.DEFAULT" />
                    <!-- 需要Intent的Data属性的scheme是lee、且host是www.fkjava.org 
                    、port是8888、且path是/mypath
                    、且type是abc/xyz才可启动该Activity -->
                    <data
                        android:scheme="lee"
                        android:host="www.fkjava.org"
                        android:port="8888"
                        android:path="/mypath"
                        android:mimeType="abc/xyz"/>
                </intent-filter>
            </activity>
        </application>
    </manifest>

    布局文件

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="匹配scheme的Intent"
            android:onClick="scheme"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="匹配scheme、host、port的Intent"
            android:onClick="schemeHostPort"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="匹配scheme、host、path的Intent"
            android:onClick="schemeHostPath"/>    
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="匹配scheme、host、port、path的Intent"
            android:onClick="schemeHostPortPath"/>
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="匹配scheme、host、port、path和type的Intent"
            android:onClick="schemeHostPortPathType"/>            
    </LinearLayout>

    activity

    package org.crazyit.intent;
    
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import android.app.Activity;
    import android.content.Intent;
    
    /**
     * Description:
     * <br/>website: <a href="http://www.crazyit.org">crazyit.org</a>
     * <br/>Copyright (C), 2001-2014, Yeeku.H.Lee
     * <br/>This program is protected by copyright laws.
     * <br/>Program Name:
     * <br/>Date:
     * @author Yeeku.H.Lee kongyeeku@163.com
     * @version 1.0
     */
    public class DataTypeAttr extends Activity
    {
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }
      //intent的Data属性,只有scheme为lee,只有第一个activity满足条件
    public void scheme(View source) { Intent intent = new Intent(); // 只设置Intent的Data属性 intent.setData(Uri.parse("lee://www.crazyit.org:1234/test")); startActivity(intent); }
      //intent的Data属性,只有scheme为lee,所以第一个activity满足条件,且该intent的Datahost ,port 与第二个activity相符
    public void schemeHostPort(View source) { Intent intent = new Intent(); // 只设置Intent的Data属性 intent.setData(Uri.parse("lee://www.fkjava.org:8888/test")); startActivity(intent);
       }
      //intent的Data属性,只有scheme为lee,所以第一个满足条件,且该intent的Data中host 和path与第三个activity相符
    public void schemeHostPath(View source) { Intent intent = new Intent(); // 只设置Intent的Data属性 intent.setData(Uri.parse("lee://www.fkjava.org:1234/mypath")); startActivity(intent); }
      //intent的Data属性,只有scheme为lee,所以第一个满足的条件;intent中Data的host,port与第二个相符,host,path与第三个相符;host,port,path与第四个相符
    public void schemeHostPortPath(View source) { Intent intent = new Intent(); // 只设置Intent的Data属性 intent.setData(Uri.parse("lee://www.fkjava.org:8888/mypath")); startActivity(intent); }
      //指定了Data和Type只有第五个相符
    public void schemeHostPortPathType(View source) { Intent intent = new Intent(); // 同时设置Intent的Data、Type属性 intent.setDataAndType(Uri.parse("lee://www.fkjava.org:8888/mypath") , "abc/xyz"); startActivity(intent); } }
  • 相关阅读:
    第二次冲刺周期站立会议(3)
    第二次冲刺周期站立会议(2)
    第二次冲刺周期站立会议(1)
    测试计划
    对各组第一次冲刺周期的评价
    团队绩效评估计划
    学校网站UI设计分析
    站立会议(10)
    Bower和Gulp集成前端资源
    Laravel的学习网站推荐
  • 原文地址:https://www.cnblogs.com/songyao/p/4076699.html
Copyright © 2020-2023  润新知