I'm trying to send one file from my app to another. I don't want to use an "app chooser", I just want to "force" that app to open the file I want.
I've tried:
Uri data = Uri.fromFile( file );
PackageManager pm = getApplicationContext().getPackageManager();
Intent ic = pm.getLaunchIntentForPackage("org.ais.archidroid");
ic.setAction(Intent.ACTION_SEND);
ic.setData(data);
ic.putExtra(Intent.EXTRA_STREAM, data);
startActivity(ic);
But this just opens the other app without the file. I have tried several combinations and googled it and haven't found anything. Maybe it's not supported.
I would suggest trying ACTION_VIEW instead of ACTION_SEND. Something like this:
Uri data = Uri.fromFile( file );
PackageManager pm = getApplicationContext().getPackageManager();
Intent ic = pm.getLaunchIntentForPackage("org.ais.archidroid");
ic.setAction(Intent.ACTION_VIEW);
ic.setData(data);
startActivity(ic);
Try setting also the launcher activity of that app you seek:
Intent intent= new Intent("org.ais.archidroid.launcheractivity");
intent.setClassName("org.ais.archidroid", "launcheractivity");
intent.setData(Uri.parse(yourdata));
startActivity(intent);
But just make sure, you typed its packageName and className right... hope this will help.
Related
I want to do a menu where u can choose the audio apps that are installed in your phone (like Youtube, Music, Skype...) so I donĀ“t know the exactly name of this type of menu (if this have a special name).
This should be what you are searching for: https://developer.android.com/training/basics/intents/sending.html
Intent intent = getPackageManager().getLaunchIntentForPackage("com.package.address");
if (intent != null) {
startActivity(launchIntent);
}
Replace com.package.address with the package name of the application you want to open.
If I understand, you would to send file to another app based on type of this file.
This code allows to send audio file to selected app.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_SEND);
File file = new File(YOUR_SONG_URI);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(Intent.createChooser(intent, "Choose app"));
More info
I need to open my .doc file in quickoffice in my app without looking for suitable apps (options).
Here I have used this
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(file);
//String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
// MimeTypeMap.getFileExtensionFromUrl(uri.toString()));
//intent.setDataAndType(uri, type == null ? "*/*" : type);
intent.setDataAndType(uri, "application/msword");
startActivity((Intent.createChooser(intent,
getString(R.string.open_using))));
This Code shows suitable target apps which i dont need actually
Remove the createChooser call, and just pass the intent to startActivity. Then it will open the default app for the mime type, assuming one is set. If none is set, it may still pop up a chooser among those apps which claim they can open it. If you want to only open quick office you can do so by activity name, but then it will fail (and possibly throw an exception) if quick office is not installed.
It worked for me.
PackageManager packageManager = getPackageManager();
Intent quickOffice = packageManager
.getLaunchIntentForPackage("com.quickoffice.android");
File sdcard = Environment.getExternalStorageDirectory();
//your file location
File file = new File(sdcard, "Meta Data.doc");
Uri path = Uri.fromFile(file);
quickOffice.setAction(Intent.ACTION_VIEW);
quickOffice.setDataAndType(path, "application/msword");// ---->application/msword
startActivity(quickOffice);
I have a list of different types of files such as pdf, audio(mp3), video etc. I want to open those file using onClick event of the list items with supported viewer or applications. For example if the selected file will be an video file then, a dialog will be appeared having a list of installed as well as the default video players as below:
Can anyone help or guide me how to do that?
you should implement a chooser, like the example below,
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");//TYPE OF THE CONTENTS,this is for text
shareIntent.putExtra(Intent.EXTRA_TEXT, noteTitle);//PUT THE EXTRA
//THIS IS THE LOGIC FOR THE CHOOSER
Intent chooser = Intent.createChooser(shareIntent,getString(R.string.share_dialog_title));
PackageManager manager = getPackageManager();
List<ResolveInfo> activities = manager.queryIntentActivities(chooser, 0);
if(activities.size() > 0) {
startActivity(chooser);
} else {
Toast.makeText(NoteListActivity.this, R.string.no_activities_for_action, Toast.LENGTH_LONG).show();
}
}
EDIT also check this question, and combine my answer with the answer of this question nad you will get the result Launching an intent for file and MIME type?
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 want to programatically launch a default file explorer to show me the contents of a folder.
I'm using this code, but it crashes:
Uri startDir = Uri.fromFile(new File("/sdcard/DCIM/Camera"));
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(startDir);
startActivity(intent);
LogCat shows "No Activity found to handle the Intent"...
What's my best option to do this? I want the user to see the contents of the folder and be able to click the files (e.g. click a video and launch it with default player, click a PDF and open it etc).
Unfortunately there seem to be no standard way to do this, I was searching for the exact same thing before and couldn't find out any solution. There are 2 alternative methods that might work for you:
1) Use a general intent and let the user pick his/her file manager
This is safe and easy but a little far from what we really want
Uri startDir = Uri.fromFile(new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/DCIM/Camera"));
Intent intent = new Intent();
intent.setData(startDir);
intent.setType("*/*");
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);
Don't use intent.setType("file/*");, it's not a standard MIME type.
2) Use Specific Intents that the famous file managers provide The well known file managers have their own custom intent filters that accept a directory path which allows simple browsing. Some of them are here: OI file manager, ES Explorer
Maybe you could check if the user have these specific file managers installed and then use this solution, else fallback to general intent.
For now these are the only two options you have. I will update this post if I find out any better solution.
Although I could not get the OI file manager to go to a specific directory, the following opens up the OI File Manager directly and goes to the last directory it was in.
Intent importFileIntent = new Intent();
importFileIntent.setType( "file/*" );
// Does nothing.
// Uri startingDir = Uri.fromFile( new File(
// Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera"));
// importFileIntent.setData( startingDirectory );
importFileIntent.setAction( Intent.ACTION_GET_CONTENT );
// Ensure that there's an activity to handle the intent.
if (importFileIntent.resolveActivity(getPackageManager()) == null) return;
startActivityForResult(importFileIntent, REQUEST_FILE_IMPORT);
If anybody has further success, I would love to hear it.