最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

android隱式意圖激活自定義界面和系統(tǒng)應(yīng)用界面的實例

 更新時間:2017年06月04日 10:20:55   投稿:jingxian  
下面小編就為大家?guī)硪黄猘ndroid隱式意圖激活自定義界面和系統(tǒng)應(yīng)用界面的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

我們也可以使用隱士意圖激活自定義的界面,并且可以攜帶數(shù)據(jù):

效果:

點擊第二個按鈕后:

點擊最后一個按鈕(激活系統(tǒng)短消息界面)后:

附代碼:

主窗體的代碼:

package com.yy.twoactivity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends Activity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  }
  
  /**
   * 點擊事件,當用戶點擊的時候跳轉(zhuǎn)到第二個界面
   * @param view
   */
  public void click(View view){
    //意圖
    Intent intent=new Intent();
    //設(shè)置包和界面,顯式意圖
    intent.setClassName(this, "com.yy.twoactivity.SecondActivity");
    //跳轉(zhuǎn)到新的設(shè)定好的界面
    startActivity(intent);
  }
  
  /**
   * 點擊事件,當用戶點擊的時候隱式意圖跳轉(zhuǎn)到第二個界面
   * @param view
   */
  public void click3(View view){
    //意圖
    Intent intent=new Intent();
    //設(shè)置包和界面,隱式意圖
    intent.setAction("com.yy.xxx");
    //設(shè)置額外的信息【非必需,和主配置文件對應(yīng)】
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    //設(shè)置數(shù)據(jù)【非必須,和主配置文件對應(yīng),可以攜帶數(shù)據(jù)】
    intent.setData(Uri.parse("yy:adbc"));
    //跳轉(zhuǎn)到新的設(shè)定好的界面
    startActivity(intent);
  }
  
  /**
   * 點擊事件,激活系統(tǒng)的應(yīng)用 程序界面
   * @param view
   */
  public void click2(View view){
    //意圖
    Intent intent=new Intent();
    //設(shè)置預(yù)打開系統(tǒng)應(yīng)用的包和界面,顯式意圖
    // cmp=com.android.gallery/com.android.camera.GalleryPicker 
    intent.setClassName("com.android.gallery", "com.android.camera.GalleryPicker");
    //跳轉(zhuǎn)到新的設(shè)定好的界面
    startActivity(intent);
  }
  
  /**
   * 點擊事件,當用戶點擊的時候隱式意圖激活系統(tǒng)短消息
   * @param view
   */
  public void click4(View view){
    //意圖
    Intent intent=new Intent();
    //設(shè)置包和界面,隱式意圖
    intent.setAction("android.intent.action.SENDTO");
    //設(shè)置額外的信息【非必需,和主配置文件對應(yīng)】
    intent.addCategory("android.intent.category.DEFAULT");
    //設(shè)置數(shù)據(jù)【非必須,和主配置文件對應(yīng),可以攜帶數(shù)據(jù)】,前綴是看短信息應(yīng)用配置文件的scheme知道的
    intent.setData(Uri.parse("sms:15588890908"));
    //跳轉(zhuǎn)到新的設(shè)定好的界面
    startActivity(intent);
  }
}

第二個窗體的代碼:

package com.yy.twoactivity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class SecondActivity extends Activity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity2);
    
    //獲取打開當前界面的意圖
    Intent intent=getIntent();
    Uri uri=intent.getData();
    //獲取到使用intent.setData(Uri.parse("yy:adbc"));攜帶的數(shù)據(jù)
    String data=uri.getSchemeSpecificPart();
    System.out.println(data);
  }
}

另外需要在AndoridManifest.xml文件中配置:

<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=".SecondActivity"
      android:label="@string/app_second_name" >
      <intent-filter>
        <action android:name="com.yy.xxx"/>
        <category android:name="android.intent.category.DEFAULT"></category>
        <data android:scheme="yy"/>
      </intent-filter>
    </activity>
  </application>

以上這篇android隱式意圖激活自定義界面和系統(tǒng)應(yīng)用界面的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

阜南县| 龙里县| 治县。| 恩平市| 颍上县| 松江区| 鹤庆县| 阳春市| 东山县| 洞头县| 安龙县| 大城县| 沅江市| 漯河市| 峨边| 盈江县| 香港 | 密山市| 长岛县| 元江| 怀集县| 洛南县| 大安市| 乡宁县| 靖江市| 长岭县| 读书| 金华市| 安陆市| 类乌齐县| 桃江县| 栖霞市| 大名县| 昔阳县| 巴中市| 稻城县| 龙游县| 丹凤县| 宿迁市| 开阳县| 霍山县|