Code Monkey home page Code Monkey logo

afilechooser's Issues

Start the FileChooserActivity directly

Hi,

sorry, that I ask with a little problem like this.

Im not able to start the FileChooserActivity directly.
At the moment it is configured like the aFileChooserExample.

private void openFile() {
    // 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
    }
}

I dont want to see the other possibilitys (Music, photos,...) and start the aFileChooser directly.

I tried with :

    private void openFile() {
        Intent in = new Intent("com.ipaulpro.afilechooser.FileChooserActivity");
        startActivityForResult(in, REQUEST_CODE);
    }

or:

    private void openFile() {
        Intent in = new Intent("android.intent.action.GET_CONTENT");
        startActivityForResult(in, REQUEST_CODE);
    }

But I get this message on start:

E/AndroidRuntime(22091): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.ipaulpro.afilechooser.FileChooserActivity }

Can someone tell me, what changes I need?

Thank you very much

java.lang.String java.io.File.getName() throws Null pointer

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getName()' on a null object reference
at com.ipaulpro.afilechooser.utils.FileUtils.getMimeType(FileUtils.java:146)

While the uri is : content://com.google.android.apps.docs.storage/document/

Unfortunately, Documents has stopped

I am using library in my project but when i select any image then it shows me an alert with Unfortunately, Documents has stopped, here i am able to get exact path of file but everytime i am getting this Document crash issue on file choose for api above kitkat.

Displaying Empty Directory in some devices

When click on Choose a File, a progress bar is shown then Empty Directory message is displayed.

I guess, FileChooserActivity is not properly loading the List of files.

  1. Samsung Galaxy s6 edge (SM-G935FD) Android 6.0.1 (23) MARSHMELLOW
  2. LG Nexus 5 (Nexus 5) Android 6.0 (23) MARSHMELLOW

Empty Directory

Build problem

The import of android.provider.DocumentsContractor is not resolved.

Google drive file - KitKat

In kitkat you can select files directly from google: content://com.google.android.apps.docs.storage/document/acc%3D4%3Bdoc%3D2279
is there a way to get the file?

public static boolean isGoogleDriveDocument(Uri uri) {
return "com.google.android.apps.docs.storage".equals(uri.getAuthority());
}

Design flaw

I have two apps into which which a added aFileChooser (patched version with extension filter and base path).

When I started the demo for testing I saw:

device-2014-01-02-140928

Now I have three identical choose files options.

That makes me wonder if there is not fundamental design flaw inside aFileChooser. I beginn to think that one library can not be an external and internal file chooser at the same time.

Creating a File filter as per file size

Rather than an issue ,it would be an enhancement
Just like filtering the files as per file type, a mechanism to filter files as per their size.
Meaning if the user wants to display images with maximum size of 5 Mb or less,then the file browser will display only those images.

Would be nice to be able to change dir into an external sd card.

I tried the example code provided, prior to integrate aFileChooser in an app of mine I'm trying to develop. I haven't been able to change directory into my external sdcard (/storage/sdcard1 or /mnt/extSdCard), remaining into the internal one (/storage/sdcard0 or /mnt/sdcard).
Other than this, It's a great opportunity to be able to use such a good coding example.
Thanks.

Include in React Native

Hi, I would like to use this in React Native.
I don't know how to include this in my project.

I have added the Jar file in /libs
but the thing i add to AndroidManifest.xml looks like this
image

I have no real experience with android development, but this is probably easy for someone that has.

Disabling Google Drive from menu

I have been looking around but can't find an answer. Is there an easy way to simply disabling Google Drive from displaying in the fileChooser? That would be a much more simple solution if it is causing an error.

Google Drive not working

Hi, as in topic.
In example app, when i select file from Google Drive returned value is null.
Box, Dropbox works fine.

Library does not update issue

Hai,
I'm facing the below issue
After deleting any files in Downloads Es Explorer or file manager in my local storage those deleted files still remains in the library changes does not reflect in aFileChooser library while opening the lib those files also shown in list.

Mime type not taken

While adding
intent.setType("video/*");
on FileUtils. createGetContentIntent()

or adding on Manifest file also like

FileChooserActivity won't consider these Mime types but other FileBrowser Application installed on the phone will take this Mime type consideration

ArrayIndexOutOfBoundsException in FileUtils#getPath if called with root of primary external storage

When the Uri content://com.android.externalstorage.documents/tree/primary%3A/document/primary%3A is fed into FileUtils#getPath, an ArrayIndexOutOfBoundsException is raised, because the docId for this URI is "primary:" and thus splitting this id on ":" gives an array with length 1

The following fixes the problem:

    if ("primary".equalsIgnoreCase(type)) {
      String path = Environment.getExternalStorageDirectory().getPath();
      if (split.length > 1) {
        path += "/" + split[1];
      }
      return path;
    }

No usage of AppCompatLibrary (V7)

When using aFileChooser at API Level < 11 ActionBar is not supported. This is no longer required because the AppCompatLibrary supports ActionBar on lower API levels.

Changing this is easy. Add the android-support-v7-appcompat library to the project, adjust a few lines of code and set Theme.AppCompat as the parent theme for all Activities.

Tested with the Example App on Android 2.3.3 in the Emulator.

Here is my Code for FileChooserActivity to achieve this.

/*

  • Copyright (C) 2013 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.afilechooser;

import java.io.File;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentManager.BackStackEntry;
import android.support.v4.app.FragmentManager.OnBackStackChangedListener;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar; // Support Lib V7
import android.support.v7.app.ActionBarActivity; // Support Lib V7
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

/**

  • Main Activity that handles the FileListFragments
    *

  • @Version 2013-06-25

  • @author paulburke (ipaulpro)
    */
    // Support Lib V7 ActionBarActivity instead of Fragment
    public class FileChooserActivity extends ActionBarActivity implements
    OnBackStackChangedListener, FileListFragment.Callbacks {

    public static final String PATH = "path";
    public static final String EXTERNAL_BASE_PATH = Environment
    .getExternalStorageDirectory().getAbsolutePath();

    private FragmentManager mFragmentManager;
    private BroadcastReceiver mStorageListener = new BroadcastReceiver() {
    @OverRide
    public void onReceive(Context context, Intent intent) {
    Toast.makeText(context, R.string.storage_removed, Toast.LENGTH_LONG).show();
    finishWithResult(null);
    }
    };

    private String mPath;

    @OverRide
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mFragmentManager = getSupportFragmentManager();
    mFragmentManager.addOnBackStackChangedListener(this);
    
    if (savedInstanceState == null) {
        mPath = EXTERNAL_BASE_PATH;
        addFragment();
    } else {
        mPath = savedInstanceState.getString(PATH);
    }
    
    setTitle(mPath);
    

    }

    @OverRide
    protected void onPause() {
    super.onPause();

    unregisterStorageListener();
    

    }

    @OverRide
    protected void onResume() {
    super.onResume();

    registerStorageListener();
    

    }

    @OverRide
    protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    outState.putString(PATH, mPath);
    

    }

    @OverRide
    public void onBackStackChanged() {

    int count = mFragmentManager.getBackStackEntryCount();
    if (count > 0) {
        BackStackEntry fragment = mFragmentManager.getBackStackEntryAt(count - 1);
        mPath = fragment.getName();
    } else {
        mPath = EXTERNAL_BASE_PATH;
    }
    
    setTitle(mPath);
    // Support Lib V7
    supportInvalidateOptionsMenu();
    

    }

    @OverRide
    public boolean onCreateOptionsMenu(Menu menu) {
    boolean hasBackStack = mFragmentManager.getBackStackEntryCount() > 0;

     // Support Lib V7
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(hasBackStack);
    actionBar.setHomeButtonEnabled(hasBackStack);
    
    return true;
    

    }

    @OverRide
    public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
    mFragmentManager.popBackStack();
    return true;
    }

    return super.onOptionsItemSelected(item);
    

    }

    /**

    • Add the initial Fragment with given path.
      */
      private void addFragment() {
      FileListFragment fragment = FileListFragment.newInstance(mPath);
      mFragmentManager.beginTransaction()
      .add(android.R.id.content, fragment).commit();
      }

    /**

    • "Replace" the existing Fragment with a new one using given path. We're

    • really adding a Fragment to the back stack.
      *

    • @param file The file (directory) to display.
      */
      private void replaceFragment(File file) {
      mPath = file.getAbsolutePath();

      FileListFragment fragment = FileListFragment.newInstance(mPath);
      mFragmentManager.beginTransaction()
      .replace(android.R.id.content, fragment)
      .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
      .addToBackStack(mPath).commit();
      }

    /**

    • Finish this Activity with a result code and URI of the selected file.
      *
    • @param file The file selected.
      */
      private void finishWithResult(File file) {
      if (file != null) {
      Uri uri = Uri.fromFile(file);
      setResult(RESULT_OK, new Intent().setData(uri));
      finish();
      } else {
      setResult(RESULT_CANCELED);
      finish();
      }
      }

    /**

    • Called when the user selects a File
      *
    • @param file The file that was selected
      */
      @OverRide
      public void onFileSelected(File file) {
      if (file != null) {
      if (file.isDirectory()) {
      replaceFragment(file);
      } else {
      finishWithResult(file);
      }
      } else {
      Toast.makeText(FileChooserActivity.this, R.string.error_selecting_file,
      Toast.LENGTH_SHORT).show();
      }
      }

    /**

    • Register the external storage BroadcastReceiver.
      */
      private void registerStorageListener() {
      IntentFilter filter = new IntentFilter();
      filter.addAction(Intent.ACTION_MEDIA_REMOVED);
      registerReceiver(mStorageListener, filter);
      }

    /**

    • Unregister the external storage BroadcastReceiver.
      */
      private void unregisterStorageListener() {
      unregisterReceiver(mStorageListener);
      }
      }

Build problem

The DocumentProvider cannot be resolved to a type

Unsupported column: _data

I have crashes with the library. Device is Nexus 5 with Android 4.4.2. Trace is
Caused by: java.lang.UnsupportedOperationException: Unsupported column: _data
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:169)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
at android.content.ContentResolver.query(ContentResolver.java:461)
at android.content.ContentResolver.query(ContentResolver.java:404)
at com.ipaulpro.afilechooser.utils.FileUtils.getDataColumn(FileUtils.java:218)
at com.ipaulpro.afilechooser.utils.FileUtils.getPath(FileUtils.java:319)

How to fix this?

afilechooser android 5.0.2

Hallo everybody,

I'm using ipaulpro.afilechooser.FileChooserActivity in my app and it work fine. But it does't work on Samsung Tab (Android 5.0.2). I can choose JPG , PNG but no PDF. Please do you know if there is a Problem on 5.0.2?

Best regards

Cannot choose file

Hi, i faced an issue when selected the file. Unfortunately i could not select the file by using the android default file chooser. If i used another file chooser (ES File Explorer) it worked.

screenshot_20160616-100803

Everything was disabled :(

NullPointerException related to ActionBar

One of my users with a Samsung Galaxy Nexus with android 4.1.1 experienced this:

java.lang.NullPointerException
at com.ipaulpro.afilechooser.FileChooserActivity.boolean onCreateOptionsMenu(android.view.Menu)(ProGuard:125)
at android.app.Activity.onCreatePanelMenu(Activity.java:2503)
at android.support.v4.app.FragmentActivity.boolean onCreatePanelMenu(int,android.view.Menu)(ProGuard:275)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
at com.android.internal.policy.impl.PhoneWindow.onKeyDownPanel(PhoneWindow.java:767)
at com.android.internal.policy.impl.PhoneWindow.onKeyDown(PhoneWindow.java:1432)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1826)
at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3733)
at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3703)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2933)
at android.os.Handler.dispatchMessage(Handler.java:119)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4873)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:528)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

string/chooser——label Not found

When i added the “FileChooserActivity” activity in manifest
i came across such an error

error: Error: No resource found that matches the given name (at 'label' with value
'@string/chooser_label').

Any help, thanks in advance

Not Working Library and Demo

I have downloaded Library and just executing Demo, but I am stuck with this problem.

11-06 09:48:15.589: E/AndroidRuntime(15228): FATAL EXCEPTION: main 11-06 09:48:15.589: E/AndroidRuntime(15228): Process: com.android.documentsui, PID: 15228 11-06 09:48:15.589: E/AndroidRuntime(15228): java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.GET_CONTENT cat=[android.intent.category.OPENABLE] typ=*/* flg=0x1000000 cmp=com.desarrollodroide.repos/com.ipaulpro.afilechooser.FileChooserActivity } from ProcessRecord{41ee8330 15228:com.android.documentsui/u0a74} (pid=15228, uid=10074) not exported from uid 10221 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.os.Parcel.readException(Parcel.java:1465) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.os.Parcel.readException(Parcel.java:1419) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2096) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.app.Activity.startActivityForResult(Activity.java:3424) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.app.Activity.startActivityForResult(Activity.java:3385) 11-06 09:48:15.589: E/AndroidRuntime(15228): at com.android.documentsui.DocumentsActivity.onAppPicked(DocumentsActivity.java:926) 11-06 09:48:15.589: E/AndroidRuntime(15228): at com.android.documentsui.RootsFragment$2.onItemClick(RootsFragment.java:183) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.widget.AdapterView.performItemClick(AdapterView.java:299) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.widget.AbsListView.performItemClick(AbsListView.java:1113) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2911) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.widget.AbsListView$3.run(AbsListView.java:3645) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.os.Handler.handleCallback(Handler.java:733) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.os.Handler.dispatchMessage(Handler.java:95) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.os.Looper.loop(Looper.java:136) 11-06 09:48:15.589: E/AndroidRuntime(15228): at android.app.ActivityThread.main(ActivityThread.java:5001) 11-06 09:48:15.589: E/AndroidRuntime(15228): at java.lang.reflect.Method.invokeNative(Native Method) 11-06 09:48:15.589: E/AndroidRuntime(15228): at java.lang.reflect.Method.invoke(Method.java:515) 11-06 09:48:15.589: E/AndroidRuntime(15228): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 11-06 09:48:15.589: E/AndroidRuntime(15228): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 11-06 09:48:15.589: E/AndroidRuntime(15228): at dalvik.system.NativeStart.main(Native Method)

Filter file types

First of all thanks for sharing this awesome piece of work :)

Hey Guys is there a way to filter file types in this library?

I mean I want to limit this chooser to select only pdf or doc files.

Is there anything like this in here already ?

Problem with Proguard

I was trying to export the example application in the project and was unable to do so. In the aFileChooserExample project, I added the following line in project.properties file -

proguard.config=proguard.cfg

Then I tried to export the project by going to Android Tools > Export signed application package. It gave the following error message -

Conversion to dalvik format failed with error 1

is it possible to set default folder in afilechooser?

I want to set a folder in internal memory to open on that folder when user select "choose file" icon.
I also, do as bellow but it does not work:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("text/plain");
Uri startDir = Uri.fromFile(new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/myfolder"));

    intent.setDataAndType(startDir,
            "vnd.android.cursor.dir/lysesoft.andexplorer.file");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    ActivityForResult(
                Intent.createChooser(intent,getString(R.string.choose_file)),
                FILE_SELECT_CODE);

Cannot receive result from started FileChooser activity

Hi Paul,

Firstly, thanks for your effort in making this FileChooser which is really neat.

However, following the way from your Readme and code from example, I have encountered problems in getting

intent result from the FilePicker which is my version of activity extends the FileChooser.

Heres the codes:

I starts the activity by:

                Intent in = new Intent(v.getContext(),
                        org.vc.FilePicker.FilePicker.class);
                in.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(in, REQUEST_CODE);

OnActivityResult:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK)
        if (requestCode == REQUEST_CODE) {
            if (data.hasExtra("tmp")) {
                String tmp = data.getStringExtra("tmp");
                Toast.makeText(this, "filename: " + tmp, Toast.LENGTH_LONG).show();
                Log.i("Filename:", tmp);
            }
        }
}

In the newly created FilePicker Activity:

 @Override
 public void finish() {
 Intent data = new Intent();
 Log.i("&&&&&&&&&& PATH", tmp);
 data.putExtra("tmp", tmp);
 setResult(RESULT_OK, data);
 super.finish();
 }

This setting turns out to be no result could be fetched by the

main Activity although the FilePicker works perfectly on picking files.

PS: for some reason, my testing Log.i(); outputs never triggers or could not be found in

logcat neither.

Thanks in advance, looking forward for you reply.

NoClassDefFoundError when using aFileChooser with my app.

Hello,

I get the exception linked below when I select the built-in aFileChooser to select a file for my app to process. The sample provided with aFileChooser works fine, however.

http://pastebin.com/hXaJ0jQ7

Instead of adding the aFileChooser project as a dependency, I copied the JAR file to my project's libs folder and added it to the build path. I did this because I host my project on Google Code and I didn't want anyone cloning my repository to have to clone other repositories as well.

Issue getting path from file located on SD card

When using the aFileChooserExample application, I will select a file located on my SD card, and the resulting toast says "File Selected: null". Is there something I have to do to properly retrieve the path from the SD card?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.