how to open other file manager apps via intent? - android

in my app i use the code below to open up the downloads and only see PDF files. But it opens up the default Android file manager and for other parts of my app to work i need to use other file managers (i am using ES File Manager) to open up instead.
How do i open up other file manager apps?
(giving the user an option to choose from multiple file manager apps helps too)
My code as of now:
public void PDF() {
PDF = (Button) findViewById(R.id.FindPDFBtn);//Finds the button in design and put it into a button variable.
PDF.setOnClickListener(//Listens for a button click.
new View.OnClickListener() {//Creates a new click listener.
#Override
public void onClick(View v) {//does what ever code is in here when the button is clicked
Intent intent = new Intent();
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select a PDF "), SELECT_PDF);
}
}
);
}

The problem with third party file explorers is that most of them don't support the same kind of intents (as they are not standardized).
For ES File explorer, check this: http://www.estrongs.com/res/develop_en.htm

Related

file chooser for Nougat or higher

I am implementing a file chooser in my android app, I am having 3 different file chooser each for AUDIO, VIDEO, IMAGE.
Its working good below android 7.0, when clicked, its going to gallery for choosing that type of file.
But in Android 7.0, when i am clicking to choose the file picker, its going to RECENT and from there manually i need to go to audio or image gallery, how can i directly go to audio gallery on clicking file chooser as its working in kitkat.
Below is my code to call the file chooser --
private void showFileChooser() {
Intent intent = new Intent();
//sets the select file to all types of files
intent.setType("audio/*");
//allows to select data and return it
intent.setAction(Intent.ACTION_GET_CONTENT);
//starts new activity to select file and return data
startActivityForResult(Intent.createChooser(intent,"Choose File to Upload.."),PICK_FILE_REQUEST);
}

Open PDF from Cloud android

I want to open a PDF File uploaded in Google Drive on click of an Imageview.
As soon as I click, the PDF should get downloaded and ask the user to open a related PDF Viewer
Now the problem is, when I click, It asks the user to open in Drive or Chrome. But I want the options should be for PDF Applications like Adobe reader, polaris office etc.
Here is My Code :
u1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String un1 = "https://drive.google.com/open?id=0B_i97Zc2yxeSNFJMVXFGQmlXYzQ&authuser=0";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(un1));
startActivity(i);
}
});
Replace i.setData(Uri.parse(un1)); with i.setDataAndType(uri, "application/pdf");, where uri is a Uri pointing to your downloaded copy of the PDF file. For example, if you downloaded the PDF file to external storage, you could use Uri.fromFile() to get a Uri pointing to the same file as does a File object.

Input and output path in Android

I am using FFMPEG to make a video editor. I stuck when selecting a folder:
1/ I will show "File Manager" to user. They can choose a folder then return a path. How can choose a folder and get its path. For example: /sdcard/videokit/.
Here is my code, I must choose a mp4 file (not a folder I want).
public void openFolder()
{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ "/sdcard/");
intent.setDataAndType(uri, "folder|video/mp4");
startActivityForResult(Intent.createChooser(intent, "Select Folder"),PICK_VIDEO_OUTPUT_REQUEST);
}
Thank you in advance!
No, you cannot use Intent to choose folder in Android. You need a dialog of your own. Luckily, there are plenty ready to use code samples available, e.g. How to select folder in android?.

Simple way to read data from html file with my app?

I'm developing an app that should be able to transfer simple data between devices.
So first step is to send some data from my app on Device 1 to Device 2. I'm using the code below:
Button btnShare = (Button)findViewById(R.id.btnShare);
btnShare.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Name:"+oldName+",Surname:"+oldName);
startActivity(sendIntent);
}
});
After the button click Android share menu appears and I select Bluetooth option. I use it to send data to Device 2 and it gets there as file with extension ".html".
Now I would like to open that file and use data stored inside in my app on second device.
I click on file in my Bluetooth folder and I choose my app from menu with suggested apps to use with html files.
My app on second device starts but I can't get data from the file.
What is the most simple way to get data with my app from that file?
Should I use ACTION_VIEW?
In the activity that is opened you need to get the data via the Intent object
Intent intent = getIntent();
Uri uri = intent.getData();
String filename = null;
if (uri!=null)
filename = uri.getPath();

Open device gallary for view only

I find this code here to open the gallery from my own btn:
btnGallery.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 0);
}
});
It works, but when I click on a photo it exit the viewer.
I guess it because the "createChooser".
How can I change it to only view the photos and not to choose them?
As far as I know this is impossible.
If you had access to a full class name of an activity to start the Gallery app you could call it as you usually do it Activity.startActivity(Context context, Class clazz). But Gallery classes is an internal API which you have no direct access to.
Well, Gallery app is accessible via throwing an appropriate Intent like the one in your sample code. By setting action name intent.setAction(Intent.ACTION_GET_CONTENT) you request the behavior you've got (browse all images, select one, get back to the caller activity with a uri of a selected image). There is also another possible action Intent.ACTION_VIEW, and if set with a uri of an image it causes Gallery to show that image for you. But that's all we can request from Gallery (there are no other predefined actions to suit your needs - just to browse images).
So, a way out is to create your own custom image browser activity.

Categories

Resources