Samsung My Files explorer: Pick file from specifie

2019-03-16 08:22发布

问题:

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);