欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android教程之intent的action屬性使用示例(intent發(fā)短信)

 更新時(shí)間:2014年01月29日 10:47:50   作者:  
這篇文章主要介紹了android中intent的action屬性使用示例,提供了使用intent撥打電話、發(fā)送短信、播放mp3的代碼

Action :規(guī)定了Intent要完成的動(dòng)作,是一個(gè)字符串常量。使用setAction()來設(shè)置Action屬性,使用getAction()來獲得Action屬性。既可以使用系統(tǒng)內(nèi)置的Action,也可以自己定義。系統(tǒng)自定義的action,如ACTION_VIEW, ACTION_EDIT, ACTION_MAIN等等。

1.自定義Action

在“目的Activity”的AndroidManifest.xml中指定action常量。

復(fù)制代碼 代碼如下:

<activity android:name=".ActionDestination">
   <intent-filter>
       <action android:name="Skywang_ACTION" />
       <category android:name="android.intent.category.DEFAULT"/>
   </intent-filter>
</activity>

<categoryandroid:name="android.intent.category.DEFAULT" />的作用是用來說明,可以通過隱式跳轉(zhuǎn)(即其它類調(diào)用setAction("Skywang_ACTION"))來找到ActionDestination這個(gè)activity。這樣,其它的類就可以通過下面的代碼跳轉(zhuǎn)到ActionDestination。跳轉(zhuǎn)時(shí),setAction的字符串"Skywang_ACTION"必須與AndroidManifest.xml中定義的"Skywang_ACTION"一致。
復(fù)制代碼 代碼如下:

Intent intent = new Intent(); 
intent.setAction("Skywang_ACTION"); 
startActivity(intent);

2系統(tǒng)Action

復(fù)制代碼 代碼如下:

// 流量網(wǎng)頁
Uri uri =Uri.parse("http://www.baidu.com");
Intent intent = newIntent(Intent.ACTION_VIEW, uri); 
startActivity(intent);
// 撥打電話
// if you want to use ACTION_DIAL, you mustadd permissin in manifest, the permission is bellow
// <uses-permissionandroid:name="android.permission.CALL_PHONE" />
Uri uri = Uri.parse("tel:12580");
Intent it = new Intent(Intent.ACTION_DIAL,uri);
startActivity(it);
// 發(fā)送短信
Uri uri = Uri.parse("smsto:13410177756");
Intent it = newIntent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "TheSMS text");
startActivity(it);
//播放mp3
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri =Uri.parse("file:///sdcard/song.mp3"); 
it.setDataAndType(uri, "audio/mp3");
startActivity(it);

相關(guān)文章

最新評(píng)論