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 Studio多渠道打包、自定義打包APK名稱
Android Studio為我們提供了簡便的方法,可以多渠道打包,一次打包所有的渠道包。這篇文章主要介紹了Android Studio多渠道打包、自定義打包APK名稱,需要的朋友可以參考下2018-01-01解決Android popupWindow設置背景透明度無效的問題
這篇文章主要介紹了解決Android popupWindow設置背景透明度無效的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08舉例講解Android應用中SimpleAdapter簡單適配器的使用
這篇文章主要介紹了Android應用中SimpleAdapter簡單適配器的使用例子,SimpleAdapter經常在ListView被使用,需要的朋友可以參考下2016-04-04Android Studio做超好玩的拼圖游戲 附送詳細注釋源碼
這篇文章主要介紹了用Android Studio做的一個超好玩的拼圖游戲,你是0基礎Android小白也能包你學會,另外附送超詳細注釋的源碼,建議收藏!2021-08-08