select only ".apk" file from file manager android - java

i am developing a app in which i want to show only apk files to user so he could select only .apk files from file manager. I found several answers but rest didnt work for me. i tried intent.setType("application/vnd.android.package-archive" Infact i am unable to restrict user even only to images.
here is my code
private void showFileChooser() {
Intent intent = new Intent();
//sets the select file to all types of files
intent.setType("application/vnd.android.package-archive");
//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);
}

Related

Android 11 use "Intent.ACTION_OPEN_DOCUMENT" select file in "Downloads" folder [duplicate]

This question already has answers here:
Android Kotlin: Getting a FileNotFoundException with filename chosen from file picker?
(5 answers)
Android - Get real path of a .txt file selected from the file explorer
(1 answer)
Closed 1 year ago.
I am struggling to access files in downloads folder that user can select.
Using the following to give user to select file
Intent intent;
if (SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
} else {
intent = new Intent(Intent.ACTION_GET_CONTENT);
}
// Filter to only show results that can be "opened", such as a
// file (as opposed to a list of contacts or timezones)
intent.addCategory(Intent.CATEGORY_OPENABLE);
// Filter to show only application/pdf, using the image MIME data type.
intent.setType(PDF_MIME_TYPE);
if (activity != null) {
activity.startActivityForResult(intent, requestCode);
}
As you might know then the following method is called when user selects the file
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
(Expected): Please see the following I can get a decent path from selecting another folder I created "fromPC"(observe it is a file named:"815" and extension "PDF"):
(Problem): When doing the exact same code but selecting "Downloads" folder I only get "873" at the end but the file name I selected was "PaymentNotification" and extension "PDF":
Reading online but nothing quite as specific as this.
So I am not sure how to let user select a file example PDF from "Downloads" folder after the scope storage change in new Android thanks in advance for the answer?
If there are a way to get a "File"(java.io) from within the "onActivityResult" method it would also solve my problem?

upload one image OR multiple image in android

How can I change my code to put an option in my application which give the user the option to choose either a single for a couple of photos to upload in their profile?
At the moment I'm using the following code ....... ,but it doesn't allow the user to choose a single image and its limits is at least 2 photos
So how should I change my code?
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "select images"), CODE_MULTIPLE_IMG_GALLERY);

Launch Microsoft Word from app

I am trying to use the Microsoft word app available for android but cant seem to find the Intent options documented
I have a file and wish to open with Word:
private void editfile(final String file, final String field) {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
Uri uri = Uri.parse(file);
intent.setDataAndType(uri,"appliction/*");
activity.startActivity(intent);
}
This launches Word, but doesn't open the selected file - in fact all the files in my storage are greyed out and not selectable (but can be selected if I run Word outside my app)
Is there an interface guide? anyone with any experience of using?

Android Select File Intent

I'm trying to pick a file via an Intent.
What I tryed till now is this:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, FILE_SELECT_CODE);
But with this, I can only pic Photos with the galery app.
My goal is to pic ANY file via the standard file manager of Android/Samsung.
This didn't work either:
String manufactures = android.os.Build.MANUFACTURER;
if(manufactures.equalsIgnoreCase("samsung"))
{
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
startActivityForResult(intent, FILE_SELECT_CODE);
}
Thx for your help!
My goal is to pic ANY file via the standard file manager of Android/Samsung.
Android does not have a "standard file manager".
If your minSdkVersion is 19 or higher, you are welcome to use the Storage Access Framework (e.g., ACTION_OPEN_DOCUMENT), which is the closest thing that Android now has to a "standard file manager".
Otherwise, you are limited to whatever ACTION_GET_CONTENT-supporting apps that the user has installed, or creating your own file-selection UI, or using one of many existing libraries for selecting files.

How to browse to file explorer in android through code

Hi I want to browse to a file explorer and select a pdf or image present in some directory.
I want the code to do the same.
the below code takes me to gallery and help me choose image but I want to move to file explorer then select file and accordingly I want the code in onactivityResult after selecting.
browsePic.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
);
startActivityForResult(i, LOAD_IMAGE_RESULTS);
}
});
I believe you can throw out an open intent for a file chooser using the following.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
try{
startActivityForResult(intent, LOAD_IMAGE_RESULTS);
} catch (ActivityNotFoundException e){
Toast.makeText(YourActivity.this, "There are no file explorer clients installed.", Toast.LENGTH_SHORT).show();
}
The trouble is however, this assumes your user has a file browser open to accepting intents installed on their device, when often no such apps are installed on a device by default.
As in the code above, you may have to throw up a dialog if no Activities exist that can accept this intent, explaining that they need to install a file browser. You could even recommend one that you know works with your application.
I hope this helps.
i think you could do something like this
File strDir = new File("/mnt/"); // where your folder you want to browse inside android
if( strDir.isDirectory()){
//do something
}

Categories