zoukankan      html  css  js  c++  java
  • Android——Intent(意图)

    //Intent的属性
    Intent in1 = new Intent();

    ComponentName componentName = new ComponentName(this,Activity2.class);

    in1.setComponent(componentName);//设置显示意图

    in1.setAction(Intent.ACTION_DIAL);//用特别的字符串规定一些功能的Activity 实现隐式意图 唯一性

    in1.addFlags(1);//自己规定标记 多个

    in1.addCategory("");//多个

    //in1.setDataAndTypeAndNormalize();Type

    Intent intent = new Intent(this,Activity2.class);

    main_layout.xml

    <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="隐式意图调用"
            android:textSize="30dp"
            android:onClick="onclick5"
    
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="隐式意图调用打电话"
            android:textSize="30dp"
            android:onClick="onclick6"
    
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="隐式意图直接拨打电话"
            android:textSize="30dp"
            android:onClick="onclick7"
    
            />
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="回到桌面"
            android:textSize="30dp"
            android:onClick="onclick8"
    
            />

    MainActivity.java

    //隐式意图的监听
           public void onclick5(View view)
        {
            //只有action的隐式意图
            Intent intent = new Intent("hello");
    
            startActivity(intent);
        }
        public void onclick6(View view)
        {
            //action的隐式意图
            //传数据  data Uri
            Uri uri = Uri.parse("tel:110");
    
            Intent intent = new Intent(Intent.ACTION_DIAL,uri);
    
            startActivity(intent);
        }
        public void onclick7(View view)
        {
            //action的隐式意图
            //传数据  data Uri
            Uri uri = Uri.parse("tel:110");
    
            Intent intent = new Intent(Intent.ACTION_CALL,uri);
    
            startActivity(intent);
        }
        public void onclick8(View view)
        {
            //action的隐式意图
    
            //回到桌面
            Intent intent = new Intent(Intent.ACTION_MAIN);
    
            intent.addCategory(Intent.CATEGORY_HOME);
    
            startActivity(intent);
        }

    AndroidManifext.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.chenshuai.test321">
    
        <uses-permission android:name="android.permission.CALL_PHONE" />
    
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="测试"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
    
            <activity android:name=".MainActivity"
                android:launchMode="standard">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name=".Activity2">
                <intent-filter>
                    <action android:name="hello" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
            <activity android:name=".Activity3">
                <intent-filter>
                    <action android:name="hello" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>

     效果

  • 相关阅读:
    元素定位方法与等待
    xpath定位的总结
    模拟登录
    shell的数组
    shell的函数
    shell的循环
    shell的流程控制语句case
    shell的while循环
    shell的if条件判断
    shell的for循环
  • 原文地址:https://www.cnblogs.com/Chenshuai7/p/5306832.html
Copyright © 2011-2022 走看看