最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

本文實(shí)例講述了Android實(shí)現(xiàn)打開(kāi)各種文件的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類(lèi),
//可用于獲取打開(kāi)以下文件的intent
//PDF,PPT,WORD,EXCEL,CHM,HTML,TEXT,AUDIO,VIDEO

示例:

//這個(gè)不行,可能是因?yàn)镻DF.apk程序沒(méi)有權(quán)限訪問(wèn)其它APK里的asset資源文件,又或者是路徑寫(xiě)錯(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è)用于打開(kāi)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è)用于打開(kāi)圖片文件的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è)用于打開(kāi)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è)用于打開(kāi)文本文件的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è)用于打開(kāi)音頻文件的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è)用于打開(kāi)視頻文件的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è)用于打開(kāi)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è)用于打開(kāi)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è)用于打開(kāi)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è)用于打開(kāi)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)容感興趣的讀者可查看本站專(zhuān)題:《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編程開(kāi)發(fā)之SD卡操作方法匯總》、《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》及《Android資源操作技巧匯總

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

相關(guān)文章

  • Android編程實(shí)現(xiàn)播放MP3功能示例

    Android編程實(shí)現(xiàn)播放MP3功能示例

    這篇文章主要介紹了Android編程實(shí)現(xiàn)播放MP3功能,結(jié)合實(shí)例形式分析了Android播放MP3功能的界面布局與功能實(shí)現(xiàn)相關(guān)操作技巧,需要的朋友可以參考下
    2017-02-02
  • Android原生定位服務(wù)LocationManager

    Android原生定位服務(wù)LocationManager

    這篇文章主要為大家介紹了Android原生定位服務(wù)LocationManager實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • Android實(shí)現(xiàn)簡(jiǎn)易計(jì)算功能

    Android實(shí)現(xiàn)簡(jiǎn)易計(jì)算功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)易計(jì)算功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • Android自定義View實(shí)現(xiàn)水波紋效果

    Android自定義View實(shí)現(xiàn)水波紋效果

    這篇文章主要為大家詳細(xì)介紹了Android自定義View實(shí)現(xiàn)水波紋效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • android WebView組件使用總結(jié)

    android WebView組件使用總結(jié)

    瀏覽器控件是每個(gè)開(kāi)發(fā)環(huán)境都具備的,這為馬甲神功提供了用武之地,windows的有webbrowser,android和ios都有webview;本篇主要介紹android的webview之強(qiáng)大,感興趣的朋友可以研究下
    2012-12-12
  • Android編程繪制圓形圖片的方法

    Android編程繪制圓形圖片的方法

    這篇文章主要介紹了Android編程繪制圓形圖片的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android通過(guò)自定義控件實(shí)現(xiàn)圖形繪制的相關(guān)技巧,需要的朋友可以參考下
    2016-02-02
  • Android實(shí)現(xiàn)瘋狂連連看游戲之狀態(tài)數(shù)據(jù)模型(三)

    Android實(shí)現(xiàn)瘋狂連連看游戲之狀態(tài)數(shù)據(jù)模型(三)

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)瘋狂連連看游戲之狀態(tài)數(shù)據(jù)模型,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Android中viewPager使用指南

    Android中viewPager使用指南

    這是谷歌官方給我們提供的一個(gè)兼容低版本安卓設(shè)備的軟件包,里面包囊了只有在安卓3.0以上可以使用的api。而viewpager就是其中之一利用它,我們可以做很多事情,從最簡(jiǎn)單的導(dǎo)航,到頁(yè)面菜單等等。那如何使用它呢
    2016-01-01
  • Android傳感器使用實(shí)例介紹

    Android傳感器使用實(shí)例介紹

    這篇文章主要為大家詳細(xì)介紹了Android傳感器的簡(jiǎn)單使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-12-12
  • android多開(kāi)器解析與檢測(cè)實(shí)現(xiàn)方法示例

    android多開(kāi)器解析與檢測(cè)實(shí)現(xiàn)方法示例

    最近有業(yè)務(wù)上的要求,要求app在本地進(jìn)行諸如軟件多開(kāi)、hook框架、模擬器等安全檢測(cè),防止作弊行為,下面這篇文章主要給大家介紹了關(guān)于android多開(kāi)器解析與檢測(cè)實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下
    2021-08-08

最新評(píng)論

普安县| 明光市| 天柱县| 张家口市| 长春市| 宣汉县| 林西县| 布拖县| 开江县| 营山县| 大洼县| 同仁县| 黄冈市| 咸阳市| 囊谦县| 临夏县| 奉新县| 文成县| 黄陵县| 永修县| 禹城市| 辉南县| 上高县| 巴中市| 拜城县| 安远县| 油尖旺区| 敖汉旗| 黄石市| 金阳县| 元阳县| 崇左市| 永川市| 保山市| 巴林右旗| 会昌县| 泸州市| 井研县| 忻城县| 任丘市| 老河口市|