How to prompt the "open with" menu after download a zip file - java

In my app I download .zip files. Is there a way when those files are downloaded, have a button/notification when clicked prompt the "open with" menu with third party compatible apps?
How to do that without knowing which zip handling apps are installed in the user phone?
Also, how to apply to apk files , to prompt app install ?

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(path);
intent.setDataAndType(Uri.fromFile(file), "application/zip");
startActivity(intent);

If you add a button to open the file, it will take care of all of this automatically.

Related

How do I open a specific folder with a file?

I'm trying to create an intent to open a folder with a file, but I still can't get access to it. When downloading, I save the file to the Downloads+"MyDirectory" folder, for example:
val destinationFolder: File = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS+"/MyDirectory//${FILE_NAME}")
request = DownloadManager.Request(url)
request.setAllowedOverRoaming(false)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,"/MyDirectory//${FILE_NAME}")
.setDestinationUri(Uri.fromFile(destinationFolder))
And I'm trying to open it like this
var path = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS+"/MyDirectory//")
val intent = Intent(Intent.ACTION_VIEW)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.setDataAndType(Uri.fromFile(path), DocumentsContract.Document.MIME_TYPE_DIR)
application.startActivity(intent)
And when I launch the application, a new folder is created, but the downloads folder opens, not my new folder. Do I want a new folder with my file to open when the intent is triggered, and not the downloads folder? How do I do this knowing the path to this folder?

Open the "Documents" directory of my app calling the Google Files app

I am developing an app and I should open the "Documents" folder of the directory of my app using the Google Files app (presumably using an intent).
In my app I have a recyclerView that, based on longClick event listener should open a certain directory calling the Google Files App.
How can I achieve this?
For Android 11+ devices:
String folder = "Documents";
String scheme = "content://com.android.externalstorage.documents/document/primary%3A" + folder;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(scheme), "vnd.android.document/root");
startActivity(intent );

How to permit the user to navigate into the File System?

I'm making a project that opens a file and reads/writes data.
I'm doing this using the code below:
File file = new File(Environment.getExternalStorageDirectory().getPath()
+ "/Project/Application/" + fileName);
It's working. The problem is I only can get this file if its path is the specific 'Project/Application' directory.
How can I allow the user to navigate into the device file system and find the file himself?
Android does not have a file chooser by itself. The only file list that Android can show natively is a ringtone list.
Here you have some solutions:
Load the file list into an array and show a dialog showing the file list, as you can read here: Choose File Dialog. Using this method you can detect when the user clicks an item that is a folder and then show a new dialog with the files inside that folder, so the user can navigate easily.
Here is a good answer to your question that has a built-in file chooser just in case that the user does not have one installed: Android file chooser
And also here you have a good library: https://code.google.com/p/android-filechooser/

how to download apk file to nand flash internal memory not having SD Card?

My code for downloading apk to SD card which is working fine in emulator and android devices having SD Card. I m developing app for android stick which has Nand Flash/Internal Flash not SD card.How can I get the path of Nand flash "download" forlder..How can I find the path of download folder in NandFlash?
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("/internalmemory/Download/newversion.apk")), "application/vnd.android.package-archive");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without /mnt/sdcard this flag android returned a intent error!
context.startActivity(intent);
How can I find the path of download folder in NandFlash?
The same way you hopefully found the "path of download folder" everywhere else:
Environment.getExternalStoragePublicStorageDirectory(Environment.DIRECTORY_DOWNLOADS)`
You can read more about getExternalStoragePublicDirectory() in the documentation. You might also consider reading the more general documentation about external storage.

Install an android application through another application

I need to create an application that will install some apk (the name is myapp.apk) file that I created. (I checked myapp.apk alone and it works fine)
I've created a folder raw inside the res folder and put the myapp.apk file there.
I added the following code to my application:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File("R.raw.myapp")), "application/vnd.android.package-archive");
But I'm getting a parse error on the emulator (eclipse android emulator).
I appreciate your help
First, R.raw.myapp is not a file. It is an integer identifier of a raw resource.
Second, you cannot install an APK from a resource (or an asset, or a ContentProvider). It must be a file on the filesystem, readable by other processes.
So, use getResources().openRawResource() to get an InputStream on your APK, write it to external storage, then use the file on external storage in your Intent.

Categories

Resources