Register Activity To Open Any File With Certain Extension

后端 未结 4 1349
一生所求
一生所求 2021-01-12 12:22

I\'ve been working on an application which is set to open a file with a specific extension. It works some times with Gmail (some files open, while some don\'t), and I can op

4条回答
  •  伪装坚强ぢ
    2021-01-12 13:16

    You need to resolve your path yourself when the scheme is content, i.e. when you receive a URI to a ContentProvider. The system will look at the mime type for your by call to ContentResolver.getType(Uri uri) before your intent filter is checked, hence you need the code below.

    Resolve the file path to your file by fetching a Cursor from the URI containing content scheme and query the _data column:

    Cursor cursor = getContentResolver().query(URI, null, null, null, null);
    if (cursor != null && cursor.moveToFirst()) { 
        int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); 
        return cursor.getString(idx);
    } 
    

    And add this intent-filter:

    
        
        
        
        
        
        
    
    

提交回复
热议问题