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