androidactionmain
❶ Android開發之Intent.Action Android中Intent的各種常見作用【轉】
1 Intent.ACTION_MAIN
String: Android.intent.action.MAIN標識Activity為一個程序的開始。比較常用。Input:nothingOutput:nothing
2 Intent.Action_CALL
【直接呼叫,在6.0之後的版本需要獲取許可權,詳見 Android開發學習之路-Android6.0運行時許可權【轉】 】
Stirng: android.intent.action.CALL呼叫指定的電話號碼。Input:電話號碼。數據格式為:tel:+phone number Output:Nothing
Intent intent=new Intent(); intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:1320010001");
startActivity(intent);
3 Intent.Action.DIAL
String: action.intent.action.DIAL調用撥號面板
Intent intent=new Intent();intent.setAction(Intent.ACTION_DIAL); //android.intent.action.DIAL
intent.setData(Uri.parse("tel:1320010001");
startActivity(intent);
Input:電話號碼。數據格式為:tel:+phone number Output:Nothing說明:打開Android的撥號UI。如果沒有設置數據,則打開一個空的UI,如果設置數據,action.DIAL則通過調用getData()獲取電話號碼。但設置電話號碼的數據格式為 tel:+phone number.
4 Intent.Action.ALL_APPS
String: andriod.intent.action.ALL_APPS列出所有的應用。Input:Nothing.Output:Nothing.
5Intent.ACTION_ANSWER
Stirng:android.intent.action.ANSWER處理呼入的電話。Input:Nothing.Output:Nothing.
6 Intent.ACTION_ATTACH_DATA
String: android.action.ATTCH_DATA別用於指定一些數據應該附屬於一些其他的地方,例如,圖片數據應該附屬於聯系人Input: DataOutput:nothing
7 Intent.ACTION_BUG_REPORT
String: android.intent.action.BUG_REPORT顯示Dug報告。Input:nothingoutput:nothing
8 Intent.Action_CALL_BUTTON
String: android.action.intent.CALL_BUTTON.相當於用戶按下「撥號」鍵。經測試顯示的是「通話記錄」Input:nothingOutput:nothing
Intent intent = new Intent(Intent.ACTION_CALL_BUTTON);startActivity(intent);
9 Intent.ACTION_CHOOSER
String: android.intent.action.CHOOSER顯示一個activity選擇器,允許用戶在進程之前選擇他們想要的,與之對應的是Intent.ACTION_GET_CONTENT.
10. Intent.ACTION_GET_CONTENT
String: android.intent.action.GET_CONTENT允許用戶選擇特殊種類的數據,並返回(特殊種類的數據:照一張相片或錄一段音)
Input: TypeOutput:URI
int requestCode = 1001;Intent intent = new Intent(Intent.ACTION_GET_CONTENT); // "android.intent.action.GET_CONTENT"
intent.setType("image/*"); // 查看類型,如果是其他類型,比如視頻則替換成 video/*,或 */*
Intent wrapperIntent = Intent.createChooser(intent, null);startActivityForResult(wrapperIntent, requestCode);
11 Intent.ACTION_VIEW
String:android.intent.action.VIEW用於顯示用戶的數據。比較通用,會根據用戶的數據類型打開相應的Activity。比如 tel:13400010001打開撥號程序,http://www.g.cn則會打開瀏覽器等。
Uri uri = Uri.parse("http://www.google.com"); //瀏覽器 Uri uri =Uri.parse("tel:1232333"); //撥號程序
Uri uri=Uri.parse("geo:39.899533,116.036476"); //打開地圖定位
Intent it = new Intent(Intent.ACTION_VIEW,uri);
startActivity(it);
//播放視頻
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/media.mp4");
intent.setDataAndType(uri, "video/*");
startActivity(intent);
//調用發送簡訊的程序
Intent it = new Intent(Intent.ACTION_VIEW);
it.putExtra("sms_body", "信息內容...");
it.setType("vnd.android-dirs-sms");
startActivity(it);
12 Intent.ACTION_SENDTO
String: android.intent.action.SENDTO
說明:發送簡訊息
//發送簡訊息 Uri uri = Uri.parse("smsto:13200100001");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "信息內容...");
startActivity(it);
//發送彩信,設備會提示選擇合適的程序發送 Uri uri = Uri.parse("content://media/external/images/media/23");
//設備中的資源(圖像或其他資源)
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body", "內容");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
startActivity(it);
//Email Intent intent=new Intent(Intent.ACTION_SEND);
String[] tos={"[email protected]"};
String[] ccs={"[email protected]"};
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_TEXT, "The email body text");
intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "Choose Email Client"));
13 Intent.ACTION_GET_CONTENT
//選擇圖片 requestCode 返回的標識
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //"android.intent.action.GET_CONTENT"
intent.setType(contentType); //查看類型 String IMAGE_UNSPECIFIED = "image/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);
//添加音頻
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);
//拍攝視頻
int rationLimit = getVideoCaptureDurationLimit(); //SystemProperties.getInt("ro.media.enc.lprof.ration", 60);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, rationLimit);
startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);
//視頻
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
Intent wrapperIntent = Intent.createChooser(intent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);
//錄音
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = "audior";
intent.setClassName("com.android.soundrecorder",
"com.android.soundrecorder.SoundRecorder");
((Activity) context).startActivityForResult(intent, requestCode);
//拍照 REQUEST_CODE_TAKE_PICTURE 為返回的標識
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //"android.media.action.IMAGE_CAPTURE";
intent.putExtra(MediaStore.EXTRA_OUTPUT, Mms.ScrapSpace.CONTENT_URI); // output,Uri.parse("content:/s/scrapSpace");
startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);
❷ 關於android.intent.action.MAIN在manifest里的使用
1、android.intent.action.MAIN決定應用程序是最先啟動的。
2、如果有多個activity都具有此許可權,那麼就應該用<intent-filter>來定義哪個activity在什麼情況下啟動。
3、如果在某個activity中不添加android.intent.action.MAIN有沒有影響這個沒有嘗試過,如果沒有應該是無法啟動的。理論上提示無許可權。
Android會根據manifest.xml是啟動相應的應用程序。
啟用應用程序的時候,會啟用對應的Activity,啟用的這些Activity也要在manifest.xml中聲明。
<intent-filter>在聲明的時候用到的,是在activity下一級,而<action>和<category>又是在<intent-filter>的下一級
<activity...
<intent-filter>...
<action...
<category...
</intent-filter>
</activity>
<intent-filter>就理解為過濾器,它指定了啟動應用程序的Intent對象的動作和類型
<actionandroid:name="android.intent.action.MAIN"/>
-->表示這個activity是主入口,換句話說,你只要啟動這個應用程序,就要首先調用這個activity
<categoryandroid:name="android.intent.category.LAUNCHER"/>
-->表示這個activity種類,要加到LAUNCHER程序列表裡。
(2)androidactionmain擴展閱讀:
任何一個C++程序都包含一個main函數,這是規定。main函數由系統直接調用,是程序執行的入口。(和C++語言中一樣)
main函數與用戶自己定義的函數都是各自獨立的模塊,即函數不能嵌套定義,通俗的說,不能在一個函數的函數體內定義另一個函數,即使在main函數中也不行。但main函數可以對用戶自己定義的函數進行調用(但main函數只能由系統調用)。用戶自己定義多個函數時,這幾個用戶自己定義的函數之間都可以互相調用。
參考自拉理由:網路-main
❸ 安卓開發點擊按鈕跳轉到另一個app
通過包名是可以打開app的, 當然最好是可以通過Action(隱式意圖打開)
private void RunApp(String packageName) {
PackageInfo pi;
try {
pi =
getPackageManager().getPackageInfo(packageName, 0);
Intent resolveIntent = new
Intent(Intent.ACTION_MAIN, null);
resolveIntent.setPackage(pi.packageName);
PackageManager pManager =
getPackageManager();
List apps =
pManager.queryIntentActivities(
resolveIntent, 0);
ResolveInfo ri =
apps.iterator().next();
if (ri != null) {
packageName =
ri.activityInfo.packageName;
String className =
ri.activityInfo.name;
Intent intent = new
Intent(Intent.ACTION_MAIN);
ComponentName cn =
new ComponentName(packageName, className);
intent.setComponent(cn);
startActivity(intent);
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
❹ android 沒有main函數,怎麼找到程序執行入口
android應用程序中,並沒有像c++和java這樣有main函數來作為應用程序的入口.android應用程序提供的是入口Activity(你打開一個應用,第一眼看到的),而非入口函數.
在AndroidManifest.xml中
給你要最先啟動的acticity寫上下面這些語句,表示這個activity就是入口
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
❺ android開發中如何設置主界面,比如我有兩個activity,如何選擇我想要的最先出現!
在AndroidManifest.xml里修改<activityandroid:name=".CdBusSearchActivity"android:label="@string/app_name"><intent-filter><actionandroid:name="android.intent.action.MAIN"/><categoryandroid:name="android.intent.category.LAUNCHER"/></intent-filter></activity><activityandroid:name=".BusInfoActivity"/>CdBusSearchActivity是主界面,如果想換成BusInfoActivity的話,只需交換兩個的名字就行
(5)androidactionmain擴展閱讀
如果intent對象包含FLAG_ACTIVITY_CLEAR_TOP 標記,當目標task中已存在與接收該intent對象的 activity類型相同的activity實例存在時,所有位於該activity對象上面的activity將被清空,這樣接收該intent的 activity就位於棧頂,可以響應到來的intent對象。
如果目標activity的運行模式為standard(默認),則目標activtiy也會被清空。因為當運行模式為standard時,總會創建新的activity對象來接收到來的intent對象。
參考資料
android開發 網路