Open a file using intent - android

I would like to open a Text file launcher from my application.
I have a byte[]/base64 data, that needs to be launch in an app based on their extension. I tried launching a text file using below code, but im unable to do so. Could any one please help me on this? Here is my code:
Uri myUri = Uri.parse(mActionResponse.getAttachmentData()); //mActionResponse.getAttachmentData() will return byte []
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setDataAndType(myUri, "text/plain");
context.startActivity(intent);
FYI i dont want to save the file in device storage.

Related

Is there a way to open a file stored in andorid assets with a specific application?

I'm trying to open a file from assets with an application using the code below:
String fileUri = "file:///android_asset/extensions/file.novabackup";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(fileUri), "application/octet-stream");
intent.setPackage("com.teslacoilsw.launcher");
startActivity(intent);
However, it does nothing and simply returns me to the MainActivity. I've also granted READ and WRITE access.

Android Custom FileChooser

In my app the user has the opportunity to import a file via an intent.
Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(new Helper(FunctionsActivity.this).getPathToAppFolder());
chooseFile.setDataAndType(uri, "*/*");
chooseFile.setType("*/*");
Intent intent = Intent.createChooser(chooseFile, getString(R.string.importDatei));
startActivityForResult(intent, REQUEST_CODE_IMPORT_FILE);
The valid files are files with the ending: .tr
These can undestood by my app.
The problem is, that the Intent shows all files in the folder:
After long searching I could not find a solution to show only .tr files. (Besides: For .xml or known file formats it is possible.)
So my idea is to write a small custom filechooser. When you click on "import", an activity opens that shows the names of all files with the extension .tr
So my question is:
Has anyone implemented something like this and can help me or does anyone has tips how to implement this the best?
I am grateful for everything that helps me further

How to create an intent to open .doc file using Polaris Viewer on Android?

I am trying to open a .doc file from my SD card using Polaris Viewer.
I keep on getting a message saying "This document cannot be opened".
weird thing is that I CAN open it from elsewhere.
I have ES File Explorer on my phone and I can open through there. It does it via Polaris Viewer so the file is obviously okay.
The only thing I can think of is that I have a problem with my intent.
Is there any way to see exactly what intent ES File Explorer sent?
This is my code (textOpenUri is a full path name of the file to be opened):
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(textOpenUri, "application/msword");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
I did a small test (just to make sure it is not defaulting to some other app) using:
List<ResolveInfo> list = getActivity().getPackageManager().queryIntentActivities(intent,0);
and I get back Polaris as the only app that can deal with the intent.
Intent intent = new Intent("android.intent.action.VIEW");
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
Uri uri = Uri.fromFile(file);
intent.setDataAndType(uri, "application/msword");
this.startActivity(intent);
startActivity(intent);

How to open the My Files folder in Android Programatically (using 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);

Android ACTION_VIDEO_CAPTURE Intent Crashes

I am using the following intent to invoke the camera and save the
recording as a specific name:
filepath = "/sdcard/testfolder/testvid.mp4";
File vidfile = new File(filepath);
Uri viduri = Uri.fromFile(vidfile);
Intent i = new
Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, viduri);
startActivity(i);
However the application keeps on crashing (The application has ....
stopped unexpectedly). But I noticed that the file has been saved with
the required name in the directory.
Any idea how can i resolve this? Basically I want to start the video
camera and save the subsequent recording in a specific directory and
name.
Thanks In Advance,
Perumal
Try with
startActivityForResult(i, 0);

Categories

Resources