導航:首頁 > 操作系統 > android打開文件intent

android打開文件intent

發布時間:2022-09-24 10:30:03

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。


⑦ android Intent啟動其它應用

可以帶別的東西。
需要com.rarlab.rar.MainActivity類的支持。
com.rarlab.rar.MainActivity可以在onCreate中通過getIntent來得到
傳入來的intent.
intent可以設置一些數據,比如Intent.putExtra("type","rar")
然後onCreate得到後,可以Intent.getStringExtra("type")

⑧ android如何打開一個文件使用安裝應用程序嗎

應用中如何調用系統所裝的軟體打開一個文件,這是我們經常碰到的問題,下面是我所用到的一種方法,和大家一起分享一下!

這個是打開文件的一個方法:

Java代碼

⑨ 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打開內置的瀏覽器。

閱讀全文

與android打開文件intent相關的資料

熱點內容
華為筆記本電腦怎麼安裝抖音app 瀏覽:410
阿里雲國際版試用的伺服器怎麼搞 瀏覽:893
java正則表達式工具 瀏覽:158
oa伺服器怎麼設置ftp 瀏覽:8
安卓如何安裝obb 瀏覽:440
QQ聊天記錄journal文件夾 瀏覽:118
蘋果公司雲伺服器地址 瀏覽:85
加密記事本手機 瀏覽:437
汽車壓縮機變頻閥 瀏覽:95
域外伺服器是什麼意思 瀏覽:639
大眾點評伺服器怎麼老卡頓 瀏覽:556
javavector與list的區別 瀏覽:316
java初始化類數組 瀏覽:303
java字元串轉換成json對象 瀏覽:647
android非阻塞socket 瀏覽:358
編譯系統概念 瀏覽:452
天眼通app能做什麼 瀏覽:557
魅族手機怎麼加密圖庫 瀏覽:8
rpa編譯器 瀏覽:572
車載雲伺服器記錄 瀏覽:740