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

Android實(shí)現(xiàn)打開各種文件的intent方法小結(jié)

 更新時(shí)間:2016年08月15日 10:36:37   作者:llyofdream  
這篇文章主要介紹了Android實(shí)現(xiàn)打開各種文件的intent方法,結(jié)合實(shí)例形式總結(jié)分析了Android針對(duì)HTML、圖片文件、pdf文件、文本文件、音頻文件、視頻文件等的intent打開方法,需要的朋友可以參考下

本文實(shí)例講述了Android實(shí)現(xiàn)打開各種文件的intent方法。分享給大家供大家參考,具體如下:

import android.app.Activity;
import Android.content.Intent;
import android.net.Uri;
import android.net.Uri.Builder;
import Java.io.File;
import android.content.Intent;
//自定義android Intent類,
//可用于獲取打開以下文件的intent
//PDF,PPT,WORD,EXCEL,CHM,HTML,TEXT,AUDIO,VIDEO

示例:

//這個(gè)不行,可能是因?yàn)镻DF.apk程序沒有權(quán)限訪問其它APK里的asset資源文件,又或者是路徑寫錯(cuò)?
//Intent it = getPdfFileIntent("file:///android_asset/helphelp.pdf");
//下面這些都OK
//Intent it = getHtmlFileIntent("/mnt/sdcard/tutorial.html");//SD卡主目錄
//Intent it = getHtmlFileIntent("/sdcard/tutorial.html");//SD卡主目錄,這樣也可以
Intent it = getHtmlFileIntent("/system/etc/tutorial.html");//系統(tǒng)內(nèi)部的etc目錄
//Intent it = getPdfFileIntent("/system/etc/helphelp.pdf");
//Intent it = getWordFileIntent("/system/etc/help.doc");
//Intent it = getExcelFileIntent("/mnt/sdcard/Book1.xls")
//Intent it = getPptFileIntent("/mnt/sdcard/download/Android_PPT.ppt");//SD卡的download目錄下
//Intent it = getVideoFileIntent("/mnt/sdcard/ice.avi");
//Intent it = getAudioFileIntent("/mnt/sdcard/ren.mp3");
//Intent it = getImageFileIntent("/mnt/sdcard/images/001041580.jpg");
//Intent it = getTextFileIntent("/mnt/sdcard/hello.txt",false);
startActivity( it );
public class MyIntent
{
//android獲取一個(gè)用于打開HTML文件的intent
 public static Intent getHtmlFileIntent( String param )
 {
  Uri uri = Uri.parse(param ).buildUpon().encodedAuthority("com.android.htmlfileprovider").scheme("content").encodedPath(param ).build();
  Intent intent = new Intent("android.intent.action.VIEW");
  intent.setDataAndType(uri, "text/html");
  return intent;
 }
//android獲取一個(gè)用于打開圖片文件的intent
 public static Intent getImageFileIntent( String param )
 {
  Intent intent = new Intent("android.intent.action.VIEW");
  intent.addCategory("android.intent.category.DEFAULT");
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  Uri uri = Uri.fromFile(new File(param ));
  intent.setDataAndType(uri, "image/*");
  return intent;
 }
 //android獲取一個(gè)用于打開PDF文件的intent
 public static Intent getPdfFileIntent( String param )
 {
  Intent intent = new Intent("android.intent.action.VIEW");
  intent.addCategory("android.intent.category.DEFAULT");
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  Uri uri = Uri.fromFile(new File(param ));
  intent.setDataAndType(uri, "application/pdf");
  return intent;
 }
//android獲取一個(gè)用于打開文本文件的intent
 public static Intent getTextFileIntent( String param, boolean paramBoolean)
{
 Intent intent = new Intent("android.intent.action.VIEW");
 intent.addCategory("android.intent.category.DEFAULT");
 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 if (paramBoolean)
 {
Uri uri1 = Uri.parse(param );
intent.setDataAndType(uri1, "text/plain");
 }
 else
 {
Uri uri2 = Uri.fromFile(new File(param ));
intent.setDataAndType(uri2, "text/plain");
 }
 return intent;
}
//android獲取一個(gè)用于打開音頻文件的intent
 public static Intent getAudioFileIntent( String param )
 {
  Intent intent = new Intent("android.intent.action.VIEW");
  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  intent.putExtra("oneshot", 0);
  intent.putExtra("configchange", 0);
  Uri uri = Uri.fromFile(new File(param ));
  intent.setDataAndType(uri, "audio/*");
  return intent;
 }
 //android獲取一個(gè)用于打開視頻文件的intent
 public static Intent getVideoFileIntent( String param )
 {
  Intent intent = new Intent("android.intent.action.VIEW");
  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  intent.putExtra("oneshot", 0);
  intent.putExtra("configchange", 0);
  Uri uri = Uri.fromFile(new File(param ));
  intent.setDataAndType(uri, "video/*");
  return intent;
 }
 //android獲取一個(gè)用于打開CHM文件的intent
 public static Intent getChmFileIntent( String param )
 {
  Intent intent = new Intent("android.intent.action.VIEW");
  intent.addCategory("android.intent.category.DEFAULT");
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  Uri uri = Uri.fromFile(new File(param ));
  intent.setDataAndType(uri, "application/x-chm");
  return intent;
 }
//android獲取一個(gè)用于打開Word文件的intent
 public static Intent getWordFileIntent( String param )
 {
  Intent intent = new Intent("android.intent.action.VIEW");
  intent.addCategory("android.intent.category.DEFAULT");
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  Uri uri = Uri.fromFile(new File(param ));
  intent.setDataAndType(uri, "application/msword");
  return intent;
 }
//android獲取一個(gè)用于打開Excel文件的intent
 public static Intent getExcelFileIntent( String param )
 {
  Intent intent = new Intent("android.intent.action.VIEW");
  intent.addCategory("android.intent.category.DEFAULT");
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  Uri uri = Uri.fromFile(new File(param ));
  intent.setDataAndType(uri, "application/vnd.ms-excel");
  return intent;
 }
//android獲取一個(gè)用于打開PPT文件的intent
 public static Intent getPptFileIntent( String param )
 {
  Intent intent = new Intent("android.intent.action.VIEW");
  intent.addCategory("android.intent.category.DEFAULT");
  intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  Uri uri = Uri.fromFile(new File(param ));
  intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
  return intent;
 }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android控件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android文件操作技巧匯總》、《Android操作SQLite數(shù)據(jù)庫(kù)技巧總結(jié)》、《Android操作json格式數(shù)據(jù)技巧總結(jié)》、《Android數(shù)據(jù)庫(kù)操作技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進(jìn)階教程》及《Android資源操作技巧匯總

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Android 滑動(dòng)定位和吸附懸停效果實(shí)現(xiàn)代碼

    Android 滑動(dòng)定位和吸附懸停效果實(shí)現(xiàn)代碼

    這篇文章主要介紹了Android 滑動(dòng)定位和吸附懸停效果實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧
    2018-08-08
  • android使用多線程更新ui示例分享

    android使用多線程更新ui示例分享

    在Android平臺(tái)中多線程應(yīng)用很廣泛,在UI更新、游戲開發(fā)和耗時(shí)處理(網(wǎng)絡(luò)通信等)等方面都需要多線程,下面是一個(gè)在線程中更新UI的代碼
    2014-01-01
  • Android 開機(jī)應(yīng)用掃描相關(guān)總結(jié)

    Android 開機(jī)應(yīng)用掃描相關(guān)總結(jié)

    本篇文章只是作為指南引導(dǎo)去看PkMS,不會(huì)貼大段代碼進(jìn)行分析,更多是基于方法分析實(shí)現(xiàn)的邏輯,另外就是代碼是基于Android 11,與Android 10之前代碼有比較大的差別。
    2021-05-05
  • Android自定義谷歌風(fēng)格ProgressBar

    Android自定義谷歌風(fēng)格ProgressBar

    這篇文章主要為大家詳細(xì)介紹了Android自定義谷歌風(fēng)格ProgressBar的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android Activity的4種啟動(dòng)模式圖文介紹

    Android Activity的4種啟動(dòng)模式圖文介紹

    這篇文章主要給大家介紹了關(guān)于Android Activity的4種啟動(dòng)模式,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Android應(yīng)用接入微信分享的實(shí)例代碼

    Android應(yīng)用接入微信分享的實(shí)例代碼

    本篇文章主要介紹了Android應(yīng)用接入微信分享的實(shí)例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。
    2017-07-07
  • Android RecyclerView區(qū)分視圖類型的Divider的實(shí)現(xiàn)

    Android RecyclerView區(qū)分視圖類型的Divider的實(shí)現(xiàn)

    本篇文章主要介紹了Android RecyclerView區(qū)分視圖類型的Divider的實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧
    2018-04-04
  • Android編程簡(jiǎn)單實(shí)現(xiàn)撥號(hào)器功能的方法

    Android編程簡(jiǎn)單實(shí)現(xiàn)撥號(hào)器功能的方法

    這篇文章主要介紹了Android編程簡(jiǎn)單實(shí)現(xiàn)撥號(hào)器功能的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android撥號(hào)器功能的實(shí)現(xiàn)原理、步驟、操作技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2017-07-07
  • Android采用GET方法進(jìn)行網(wǎng)絡(luò)傳值

    Android采用GET方法進(jìn)行網(wǎng)絡(luò)傳值

    這篇文章主要為大家詳細(xì)介紹了Android采用GET方法進(jìn)行網(wǎng)絡(luò)傳值的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android TextWatcher內(nèi)容監(jiān)聽死循環(huán)案例詳解

    Android TextWatcher內(nèi)容監(jiān)聽死循環(huán)案例詳解

    這篇文章主要介紹了Android TextWatcher內(nèi)容監(jiān)聽死循環(huán)案例詳解,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08

最新評(píng)論