Intent打開各類類型的文件

須要用到Intent.setDataAndType(path,type)函數
模板:
//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;
  }
 
打開不一樣類型的文件只須要修改參數type便可:
打開APK——application/vnd.android.package-archive
打開PPT——application/vnd.ms-powerpoint
打開Excel——application/vnd.ms-excel
打開Word——application/msword
打開CHM——application/x-chm
打開文本txt——text/plain
打開PDF——application/pdf
打開VCF——text/x-vcard
打開SWF——flash/*
相關文章
相關標籤/搜索