2012-02-16 112 views

回答

0

你可以嘗試這樣的事情連着你要處理的Intent活動。 AFAIK,處理特定文件擴展名的唯一方法是使用pathPattern,因爲我不相信您可以保證郵件應用程序將如何設置他們無法識別的文件的MIME類型。

<intent-filter> 
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 
    <data android:scheme="file" /> 
    <data android:pathPattern=".*\\.shtml" /> 
</intent-filter> 

與AOSP捆綁的電子郵件應用程序的推斷從附加文件的MIME類型,因此,如果它不能找到一個在靜態地圖,它將使用application/xxx,所以你也可以嘗試

<intent-filter> 
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 
    <data android:scheme="file" /> 
    <data android:mimeType="application/shtml" /> 
</intent-filter> 

如果郵件應用使用不同的格式(如content://),則兩種情況下的scheme屬性可能都是不必要的或阻礙的,所以如果不起作用,請嘗試省略該部分。

HTH

0

這是我從電子郵件獲取附件的最新版本。如果你使用它,如果你的源代碼保存了我的名字,它會很酷。

if (intentaction != null) { 
     if (intentaction.equals("android.intent.action.VIEW")) { 

      Uri data = intent.getData(); 
      Uri u; 

      if (data != null) { 
       try { 
        pathname = data.getPath(); 
        File f = new File(pathname); 
        boolean b = f.exists(); 
        if (!b) { 
         pathname = null; 
        } 
       } catch (Exception e) { 
        pathname = null; 
       } 
       if (pathname == null) { 
        try { 
         is = new BufferedInputStream(getContentResolver() 
           .openInputStream(data)); 
         _is = new BufferedInputStream(getContentResolver() 
           .openInputStream(data)); 
         // _savefile = true; 
        } catch (FileNotFoundException e) { 

         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
        Cursor c = getContentResolver().query(data, null, null, 
          null, null); 
        if (c != null) { 
         c.moveToFirst(); 
         int fileNameColumnId = c 
           .getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME); 
         if (fileNameColumnId >= 0) { 
          _previewFileName = c 
            .getString(fileNameColumnId); 
         } 
         if (_previewFileName == null) { 
          fileNameColumnId = c 
            .getColumnIndex(MediaStore.MediaColumns.DATA); 
          if (fileNameColumnId >= 0) { 
           pathname = c.getString(fileNameColumnId); 
           File f = new File(pathname); 
           boolean b = f.exists(); 
           if (b) { 
            try { 
             if (is != null) { 
              is.close(); 
             } 
            } catch (IOException e) { 
             // TODO Auto-generated catch block 
             e.printStackTrace(); 
            } 
            is = null; 
            try { 
             if (_is != null) { 
              _is.close(); 
             } 
            } catch (IOException e) { 
             // TODO Auto-generated catch block 
             e.printStackTrace(); 
            } 
            _is = null; 
           } else { 
            pathname = null; 
           } 
          } 
         } 
        } 
       } 
      } 
     } 
    } 

    // If we have an attachment 
    if (is != null) { 
     k = new KmlSummary(is); 
    } else if (pathname != null) { 
     k = new KmlSummary(pathname); 

好運