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

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

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

本文實例講述了Android實現(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

示例:

//這個不行,可能是因為PDF.apk程序沒有權限訪問其它APK里的asset資源文件,又或者是路徑寫錯?
//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)內部的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獲取一個用于打開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獲取一個用于打開圖片文件的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獲取一個用于打開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獲取一個用于打開文本文件的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獲取一個用于打開音頻文件的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獲取一個用于打開視頻文件的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獲取一個用于打開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獲取一個用于打開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獲取一個用于打開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獲取一個用于打開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;
 }
}

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

希望本文所述對大家Android程序設計有所幫助。

相關文章

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

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

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

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

    在Android平臺中多線程應用很廣泛,在UI更新、游戲開發(fā)和耗時處理(網絡通信等)等方面都需要多線程,下面是一個在線程中更新UI的代碼
    2014-01-01
  • Android 開機應用掃描相關總結

    Android 開機應用掃描相關總結

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

    Android自定義谷歌風格ProgressBar

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

    Android Activity的4種啟動模式圖文介紹

    這篇文章主要給大家介紹了關于Android Activity的4種啟動模式,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-11-11
  • Android應用接入微信分享的實例代碼

    Android應用接入微信分享的實例代碼

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

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

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

    Android編程簡單實現(xiàn)撥號器功能的方法

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

    Android采用GET方法進行網絡傳值

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

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

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

最新評論