Hello, I was shown an interesting library afileChooser

He catches everything (even with the help of ES Explorer) but does not want to get from the memory card. If you click item Video or gallery and select a video or image from a memory card, the link returns but does not want to return directly. What could be faulty? And how to fix? I chose the file from the memory card result program interface

/* * Copyright (C) 2012 Paul Burke * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.ipaulpro.afilechooserexample; import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; import com.ipaulpro.afilechooser.utils.FileUtils; /** * @author paulburke (ipaulpro) */ public class FileChooserExampleActivity extends Activity { private static final String TAG = "FileChooserExampleActivity"; private static final int REQUEST_CODE = 6384; // onActivityResult request // code @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create a simple button to start the file chooser process Button button = new Button(this); button.setText(R.string.choose_file); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Display the file chooser dialog showChooser(); } }); setContentView(button); } private void showChooser() { // Use the GET_CONTENT intent from the utility class Intent target = FileUtils.createGetContentIntent(); // Create the chooser Intent Intent intent = Intent.createChooser( target, getString(R.string.chooser_title)); try { startActivityForResult(intent, REQUEST_CODE); } catch (ActivityNotFoundException e) { // The reason for the existence of aFileChooser } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_CODE: // If the file selection was successful if (resultCode == RESULT_OK) { if (data != null) { // Get the URI of the selected file final Uri uri = data.getData(); Log.i(TAG, "Uri = " + uri.toString()); try { // Get the file path from the URI final String path = FileUtils.getPath(this, uri); Toast.makeText(FileChooserExampleActivity.this, "File Selected: " + path, Toast.LENGTH_LONG).show(); } catch (Exception e) { Log.e("FileSelectorTestActivity", "File select error", e); } } } break; } super.onActivityResult(requestCode, resultCode, data); } } 
  • Show ____ code - mifkamaz
  • This is an example from the author and the memory card does not work (flash drive by the way, too) - Dmitry Berezhnoy
  • And what is contained in the variable uri? Is she null too? - mifkamaz
  • The variable is not null since data is not null, it contains Uri data. + All this works well with built-in memory - Dmitry Berezhnoy
  • однако напрямую возвращать не хочет - what does it mean directly? - post_zeew

1 answer 1

This is not a fault but a feature :)

Starting with KitKat, access to the memory card for applications signed by mere mortals is limited. You need to have the signature of the vendor of the device or Google itself :)

Zillion a thousand times about this already written

Discussion of this problem in relation to aFileChooser - here

Speaking in essence, there is no access to arbitrary files on an external memory card between KitKat and LolliPop - and the point is not in aFileChooser, but in principle.

Update

For Android> = 6.0, the problem can be solved by providing runtime permission for access to the memory card.

  • I checked the program on 4.2.2, it looks completely different (if you use ES Explorer to select a file, for example, subtitles) then the link returns, and if the video is not. Here the fact is that it does not return everything even to 4.2.2 - Dmitry Berezhnoy
  • I made a correction from the githab (but this adjustment does not work for lilipop) it was written about it, + I checked - Dmitry Berezhnoy
  • And it will not work ... It will work only with N - Barmaley
  • I advise what? I'm new to this .. - Dmitry Berezhnoy
  • see the answer update - Barmaley