Samsung My Files explorer: Pick file from specified folder

感情迁移 提交于 2019-12-03 14:25:21

问题


I'm using the following code to open Samsung's My Files application to pick a file...

  public void openFileBrowser( ) {
        Intent intent = new Intent( "com.sec.android.app.myfiles.PICK_DATA" );
        try {
            startActivityForResult( intent, PICKFILE_RESULT_CODE );
        } catch ( ActivityNotFoundException e ) { 
            e.printStackTrace( );
            Log.log( Log.ERROR, TAG + "MyFiles is not installed !!" );
        }
    }   

this opens My Files application and lets user choose a file through it.
However, I wish to open a particular folder on device's external memory... and let user choose a file from there.... I tried achieving this by doing...

 public void openFileBrowser( ) {
        Intent intent = new Intent( "com.sec.android.app.myfiles.PICK_DATA" );
        File root = new File( Environment.getExternalStorageDirectory( ).getPath( ) + "/MyFolder" );
        Uri uri = Uri.fromFile( root ); 
        intent.setData( uri );        
        try {
            startActivityForResult( intent, PICKFILE_RESULT_CODE );
        } catch ( ActivityNotFoundException e ) {
            e.printStackTrace( );
            Log.log( Log.ERROR, TAG + "MyFiles is not installed !!" );
        }
    }    

But I get an exception as :

 W/System.err(14682): android.content.ActivityNotFoundException: No Activity found to    handle Intent { act=com.sec.android.app.myfiles.PICK_DATA dat=file:///storage   /emulated/0/MyFolder }    

Can someone please help me with this?
Thank you!


回答1:


You can set specify the startlocation in samsung Intent by specifying the FOLDERPATH like below.

intent.putExtra("FOLDERPATH", path);   


来源:https://stackoverflow.com/questions/21721628/samsung-my-files-explorer-pick-file-from-specified-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!