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

點擊第二個按鈕后:

點擊最后一個按鈕(激活系統(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);
}
/**
* 點擊事件,當用戶點擊的時候跳轉到第二個界面
* @param view
*/
public void click(View view){
//意圖
Intent intent=new Intent();
//設置包和界面,顯式意圖
intent.setClassName(this, "com.yy.twoactivity.SecondActivity");
//跳轉到新的設定好的界面
startActivity(intent);
}
/**
* 點擊事件,當用戶點擊的時候隱式意圖跳轉到第二個界面
* @param view
*/
public void click3(View view){
//意圖
Intent intent=new Intent();
//設置包和界面,隱式意圖
intent.setAction("com.yy.xxx");
//設置額外的信息【非必需,和主配置文件對應】
intent.addCategory(Intent.CATEGORY_DEFAULT);
//設置數據【非必須,和主配置文件對應,可以攜帶數據】
intent.setData(Uri.parse("yy:adbc"));
//跳轉到新的設定好的界面
startActivity(intent);
}
/**
* 點擊事件,激活系統(tǒng)的應用 程序界面
* @param view
*/
public void click2(View view){
//意圖
Intent intent=new Intent();
//設置預打開系統(tǒng)應用的包和界面,顯式意圖
// cmp=com.android.gallery/com.android.camera.GalleryPicker
intent.setClassName("com.android.gallery", "com.android.camera.GalleryPicker");
//跳轉到新的設定好的界面
startActivity(intent);
}
/**
* 點擊事件,當用戶點擊的時候隱式意圖激活系統(tǒng)短消息
* @param view
*/
public void click4(View view){
//意圖
Intent intent=new Intent();
//設置包和界面,隱式意圖
intent.setAction("android.intent.action.SENDTO");
//設置額外的信息【非必需,和主配置文件對應】
intent.addCategory("android.intent.category.DEFAULT");
//設置數據【非必須,和主配置文件對應,可以攜帶數據】,前綴是看短信息應用配置文件的scheme知道的
intent.setData(Uri.parse("sms:15588890908"));
//跳轉到新的設定好的界面
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"));攜帶的數據
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)應用界面的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Android List(集合)中的對象以某一個字段排序案例
這篇文章主要介紹了Android List(集合)中的對象以某一個字段排序案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08
Flutter使用AnimationController實現控制動畫
這篇文章主要想帶大家來嘗試一下Flutter如何使用AnimationController實現一個拖拽圖片,然后返回原點的動畫,感興趣的可以了解一下2023-05-05
Android高級組件ImageSwitcher圖像切換器使用方法詳解
這篇文章主要為大家詳細介紹了Android高級組件ImageSwitcher圖像切換器的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-12-12

