0

I am trying to use the Dropbox Chooser Api in android app to allow the user to choose files from Dropbox. I was able to launch the Dropbox Chooser successfully from the fragment, but after selecting the file, it shows "Creating link..." and then returns to fragment. I've overridden onActivityresult() method to get the information about the selected file.But, unfortunately the onActivityresult() is not being invoked and I'm not able to download the selected file using download manager.

videos_fragment.java

   @Override
   public void super.onActivityResult(int requestCode, int resultCode, Intent data){
    if (requestCode == DBX_CHOOSER_REQUEST){
        if (resultCode == Activity.RESULT_OK){
            DbxChooser.Result result = new DbxChooser.Result(data);

            Log.i("main", "Link to selected file: " + result.getLink());

            // Handle the result
            Toast.makeText(getContext(),"Successful",Toast.LENGTH_LONG).show();

            DownloadManager.Request request = new DownloadManager.Request(result.getLink());
            request.setDescription("Downloading from App");
            request.setTitle("Downloading..");
            // in order for this if to run, you must use the android 3.2 to compile your app
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                request.allowScanningByMediaScanner();
                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
            }


     // get download service and enqueue file
            DownloadManager manager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
            manager.enqueue(request);
        }
        else {
            Toast.makeText(getContext(),"Error connecting Dropbox",Toast.LENGTH_LONG).show();
        }
    }
    else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

Code to open dropbox dialog

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    myView = inflater.inflate(R.layout.videos_layout,container,false);
    mChooser = new DbxChooser("APP_KEY");
    mchooser_button= (Button)myView.findViewById(R.id.chooser_button);
    mchooser_button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mChooser.forResultType(DbxChooser.ResultType.DIRECT_LINK).launch(getActivity(),DBX_CHOOSER_REQUEST);
        }
    });
    return myView;
}
A.Mujeeb
  • 63
  • 10
  • can you post the code you wrote to open the DropBox file chooser dialog? – FunkSoulBrother Jan 16 '16 at 20:45
  • @FunkSoulBrother I've added in description. – A.Mujeeb Jan 16 '16 at 20:51
  • Possible duplicate of [onActivityResult not being called in Fragment](http://stackoverflow.com/questions/6147884/onactivityresult-not-being-called-in-fragment) – logcat Jan 16 '16 at 20:55
  • You should try to run the code on a real device while it's connected to your computer and review the LogCat output in order to see if there is any problem. Have you added the required permissions to the Manifest file? Have you tried to run the DropBox sample file chooser sample and compare the code to yours? – FunkSoulBrother Jan 16 '16 at 20:57
  • @logcat I am using dropbox chooser not camera intent + there is no startActivityResult command in my code. I searched whole stackoverflow and then posted my question. – A.Mujeeb Jan 16 '16 at 20:58
  • @FunkSoulBrother I am running it on real device, logcat is not showing anything suspicious but i didnt add any permission to the manifest file. – A.Mujeeb Jan 16 '16 at 21:00

2 Answers2

1

You must add <uses-permission android:name="android.permission.INTERNET"></uses-permission> to your Manifest file (taken from https://www.dropbox.com/developers-v1/core/sdks/android).

If you plan on downloading files - you should consider where you are going to write them to and add proper permissions as per http://developer.android.com/training/basics/data-storage/files.html.

Good luck!

FunkSoulBrother
  • 2,057
  • 18
  • 27
  • I presume you followed the instruction on the DropBox developer support site, so I would suggest to try the code on another device, try a new API_KEY, and check dependencies that may cause problems running DropBox. – FunkSoulBrother Jan 16 '16 at 22:07
1

finally solved this !!!

all i need to do was write OnActivityResult method in mainactivity class not in fragment java.

A.Mujeeb
  • 63
  • 10