① 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實現通過意圖來打開文件的代碼 (比如我這里有一個txt文本我需要通過第三方軟體打開
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "text/plain");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
③ Android中怎麼實現打開文件時彈出一個打開方式可供選擇的框。
這個是隱私Intent調用,沒有指定明確的Activity,而是設置了條件,只要符合都可以響應。
像你說的這種是根據文件類型做條件來判斷,可以通過Intent的setDataAndType方法實現。
這個Type是指MIME Type,網上有文件名後綴與MIME類型的對照表,可以參考。
提供一個打開內存儲根目錄下1.txt文件的樣例代碼,僅供參考(前提是沒給txt文件設置默認的打開應用)
java">Intentintent=newIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(Environment.getExternalStorageDirectory()+"/1.txt"),"text/plain");
startActivity(intent);
④ android 如何使用Intent跳轉到文件管理器指定目錄。不要再復制
intent
intent
=
new
intent();
intent.setaction("action");//這個地方action換成你要跳轉到的文件管理器的action
intent.addcategory("category");//這個地方category換成你要跳轉到的文件管理器的category
startactivity(intent);
android跳轉到另一個應用都是一樣的,只是設置的action與category跟據跳轉的應用不同有所不同。
⑤ android 怎麼用intent打開文件管理器
intent.getData()就能獲取文件的url,這個url格式一般為file:///xxxxx..xxxx
⑥ 安卓程序中intent是怎麼跳轉的
Intent分為顯示和隱式Intent。
一個顯式Intent明確的指定了要啟動的組件名稱,比如Activity名稱或者Service的名稱。創建一個顯式的Intent必須定義Component屬性,其他的屬性可選。下面的例子是創建一個Service在app中,名字叫DownloadService,功能是從網路上下載文件,你可以通過下面的代碼來啟動它:
IntentmIntent=newIntent(this,MyActivity.class);
downloadIntent.setData(mData);
startService(mIntent);//跳轉到指定Activity
一個隱式的Intent定義了將要執行的動作,任何在設備上的app都可以響應這個動作。用隱式Intent的非常的有用,當你的app不能處理某些請求動作時,但是系統中的其他應用有這個處理的能力,用戶就能方便的利用其他應用完成這個操作。比如你用網路雲盤下載了一個pdf文檔,你在點擊打開這個文檔的時候網路雲盤是無法打開的,但是也許你系統上安裝有其他的能打開pdf文檔的閱讀器,這個時候就會彈出一個對話框,列舉了可以打開pdf文檔的應用程序,你可以自由選擇一個應用程序打開你下載的文檔。例如下面查看文檔的例子:
IntentsendIntent=newIntent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,textMessage);
sendIntent.setType(HTTP.PLAIN_TEXT_TYPE);//"text/plain"MIMEtype
if(sendIntent.resolveActivity(getPackageManager())!=null){
startActivity(sendIntent);
}
⑦ android Intent啟動其它應用
可以帶別的東西。
需要com.rarlab.rar.MainActivity類的支持。
com.rarlab.rar.MainActivity可以在onCreate中通過getIntent來得到
傳入來的intent.
intent可以設置一些數據,比如Intent.putExtra("type","rar")
然後onCreate得到後,可以Intent.getStringExtra("type")
⑧ android如何打開一個文件使用安裝應用程序嗎
應用中如何調用系統所裝的軟體打開一個文件,這是我們經常碰到的問題,下面是我所用到的一種方法,和大家一起分享一下!
這個是打開文件的一個方法:
Java代碼
/**
*打開文件
*@paramfile
*/
privatevoidopenFile(Filefile){
Intentintent=newIntent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//設置intent的Action屬性
intent.setAction(Intent.ACTION_VIEW);
//獲取文件file的MIME類型
Stringtype=getMIMEType(file);
//設置intent的data和Type屬性。
intent.setDataAndType(/*uri*/Uri.fromFile(file),type);
//跳轉
startActivity(intent);
}
/**
*根據文件後綴名獲得對應的MIME類型。
*@paramfile
*/
privateStringgetMIMEType(Filefile){
Stringtype="*/*";
StringfName=file.getName();
//獲取後綴名前的分隔符"."在fName中的位置。
intdotIndex=fName.lastIndexOf(".");
if(dotIndex<0){
returntype;
}
/*獲取文件的後綴名*/
Stringend=fName.substring(dotIndex,fName.length()).toLowerCase();
if(end=="")returntype;
//在MIME和文件類型的匹配表中找到對應的MIME類型。
for(inti=0;i<MIME_MapTable.length;i++){//MIME_MapTable??在這里你一定有疑問,這個MIME_MapTable是什麼?
if(end.equals(MIME_MapTable[i][0]))
type=MIME_MapTable[i][1];
}
returntype;
}
MIME_MapTable是所有文件的後綴名所對應的MIME類型的一個String數組:
Java代碼
privatefinalString[][]MIME_MapTable={
//{後綴名,MIME類型}
{".3gp","video/3gpp"},
{".apk","application/vnd.android.package-archive"},
{".asf","video/x-ms-asf"},
{".avi","video/x-msvideo"},
{".bin","application/octet-stream"},
{".bmp","image/bmp"},
{".c","text/plain"},
{".class","application/octet-stream"},
{".conf","text/plain"},
{".cpp","text/plain"},
{".doc","application/msword"},
{".docx","application/vnd.openxmlformats-officedocument.wordprocessingml.document"},
{".xls","application/vnd.ms-excel"},
{".xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"},
{".exe","application/octet-stream"},
{".gif","image/gif"},
{".gtar","application/x-gtar"},
{".gz","application/x-gzip"},
{".h","text/plain"},
{".htm","text/html"},
{".html","text/html"},
{".jar","application/java-archive"},
{".java","text/plain"},
{".jpeg","image/jpeg"},
{".jpg","image/jpeg"},
{".js","application/x-javascript"},
{".log","text/plain"},
{".m3u","audio/x-mpegurl"},
{".m4a","audio/mp4a-latm"},
{".m4b","audio/mp4a-latm"},
{".m4p","audio/mp4a-latm"},
{".m4u","video/vnd.mpegurl"},
{".m4v","video/x-m4v"},
{".mov","video/quicktime"},
{".mp2","audio/x-mpeg"},
{".mp3","audio/x-mpeg"},
{".mp4","video/mp4"},
{".mpc","application/vnd.mpohun.certificate"},
{".mpe","video/mpeg"},
{".mpeg","video/mpeg"},
{".mpg","video/mpeg"},
{".mpg4","video/mp4"},
{".mpga","audio/mpeg"},
{".msg","application/vnd.ms-outlook"},
{".ogg","audio/ogg"},
{".pdf","application/pdf"},
{".png","image/png"},
{".pps","application/vnd.ms-powerpoint"},
{".ppt","application/vnd.ms-powerpoint"},
{".pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation"},
{".prop","text/plain"},
{".rc","text/plain"},
{".rmvb","audio/x-pn-realaudio"},
{".rtf","application/rtf"},
{".sh","text/plain"},
{".tar","application/x-tar"},
{".tgz","application/x-compressed"},
{".txt","text/plain"},
{".wav","audio/x-wav"},
{".wma","audio/x-ms-wma"},
{".wmv","audio/x-ms-wmv"},
{".wps","application/vnd.ms-works"},
{".xml","text/plain"},
{".z","application/x-compress"},
{".zip","application/x-zip-compressed"},
{"","*/*"}
};
⑨ Android如何觸發intent打開指定目錄
Android觸發intent打開指定目錄的步驟:
1、android系統內置了很多應用,包括電話撥號,簡訊,瀏覽器等,這里創建一個簡單的Android程序,調用內置的瀏覽器打開指定的地址。
2、對應的layout xml為:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/btnGo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="46dp"
android:text="@string/btnTitle_go" />
<EditText
android:id="@+id/txtUri"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnGo"
android:layout_alignBottom="@+id/btnGo"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/btnGo"
android:ems="10"
android:text="http://junqilian.cnblogs.com" >
<requestFocus />
</EditText>
</RelativeLayout>
3、Java代碼實現如下,主要是給EditText添加一個OnKeyListener,處理在editText裡面按回車鍵,給button添加一個onClickListener,觸發到OpenBroswer函數,通過intent打開內置的瀏覽器。