I am doing an Android file explorer. How can I execute a file?
For example : "/xxx/xxx/image.jpg"
I need to display the image in the default android system image viewer when the user clicks on the name of the file.
You can use an intent to do that.
Intent intent = new Intent();
//Action View to see an image in default native app in your device.
intent.setAction(Intent.ACTION_VIEW);
//The path to see your image.
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);
Without knowing much about the code itself you can try with:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "your_image_path.jpg"), "image/*");
startActivity(intent);
ACTION_VIEW as per Android Documentation:
Display the data to the user. This is the most common action performed
on data -- it is the generic action you can use on a piece of data to
get the most reasonable thing to occur.
Related
Hi i have tried different ways to set my downloaded images from server as wallpaper using the native android intent in flutter but so far i am unable to implement it.
I have tried the intent package from pub.dev flutter but this code doesn't make my image pass through intent.
android_intent. Intent()
..setAction(android_action.Action.ATTACH_DATA)
..setData(outputFileUri)
//..putExtra(Extra.EXTRA_STREAM, outputFileUri)
..addFlag(1)
..setType('image/*')
..startActivity().catchError((e) => print(e));
Anyway to fix this would be really helpful. I am also sharing the functionality i want like in the image
t,
This should work for your situation:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(uri, "image/*");
intent.putExtra("mimeType", "image/*");
this.startActivity(Intent.createChooser(intent, "Set as:"));
It's also independent of the image data type.
I'm trying to make my own file manager for android.
I am wondering how I could asks the user to choose the application he wants to use open a file. like when you are opening a .doc file and you have a bunch of .doc file readers. How would I be able to retrieve the list of apps that the user can use to read/open a file?
Try this code
Uri uri = Uri.parse("Your file name: //"+file.getAbsolutePath());
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
String type = "application/msword";
intent.setDataAndType(Uri.fromFile(file), type);
startActivity(intent);
You should use implicit intent for your purpose. Below is the sample code for giving options to play a video file
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("https://youtu.be/jxoG_Y6dvU8"), "video/*");
startActivity(Intent.createChooser(intent, "Complete action using"));
I hope it will help you out. For further details you may refer android official documentation as mentioned in below link
https://developer.android.com/training/basics/intents/sending.html#AppChooser
I think you can try this
Intent in= new Intent(Intent.ACTION_MAIN);
in.setComponent(new ComponentName("com.package.address","com.package.address.MainActivity"));
startActivity(in);
Hey I am new in android I have a requirement to choose pdf files using Intent. I am using this code to set type of MIME.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("pdf/*")
But it's not working the way I want, please provide me any suggestions or can I make some changes to the existing code.
Do this intent.setType("application/pdf");
Try Below Code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
I am using the below code which opens up the Gallery, Music Player, Dropbox and Contacts, i want the My Files folder to get open programatically, please let me know if there are any specific intent parameters i need to pass to get the File Manager open.
if it is not possible through intent then please give me a snippet or an hint to open the My Files folder programatically.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
Intent i = Intent.createChooser(intent, "View Default File Manager");
startActivityForResult(i, CHOOSE_FILE_REQUESTCODE);
Thanks.
You can use this code to file the files.
int PICKFILE_RESULT_CODE=1;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent,PICKFILE_RESULT_CODE);
this will help you to browse the files from your storage.
Its best that you include a library in your project which handles this scenario.
This worked for me:
This library shows the list of third-party apps. It also has its own file browser for selecting files.
Bad thing is, most Android distributions may or may not ship with a file manager, and even so, may be not with the one which handles CHOOSE_FILE_REQUESTCODE.
So, you are left to create your own file picker activity. Luckily there are many ready made ones available:
http://code.google.com/p/android-filechooser/
https://developers.inkfilepicker.com/docs/android/
If you want to open samsung My Files application try this below code.
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
You have to specifically mention the package name of the explorer application. Please find the example below to open a specific folder in ES Explorer.
public void openfolderInexplorer(String path){
Intent intent = this.getPackageManager().getLaunchIntentForPackage("com.estrongs.android.pop");
if (intent != null) {
// If the application is avilable
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.parse(path);
intent.setDataAndType(uri, "resource/folder");
this.startActivity(intent);
} else {
// Play store to install app
intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("market://details?id=" +
"com.estrongs.android.pop"));
this.startActivity(intent);
}
try this below code. if any file manager available , then it will pop up in a form of menu to choose appropriate for the user.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
I've a sequence of image paths on my sd card and I display them on a list.
I'd like to associate the onitemclick to image visualization and, rather than create my own activity, I wanted to know if there was an intent which, given an image path, displays it.
This solution assumes that you have the path of your image:
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "image/png");
startActivity(intent);