Samsung My Files explorer: Pick file from specifie

2019-03-16 08:07发布

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条回答
我欲成王,谁敢阻挡
2楼-- · 2019-03-16 08:44

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

intent.putExtra("FOLDERPATH", path);   
查看更多
登录 后发表回答