2

I have a zip file which was downloaded from url and its path is set to /storage/emulated/0/myapp/downloadedfile.zip

Now I would like to open this zip file via choose intent to list the available apps to open the downloaded file.

I have set this in manifest:

 <activity
      android:name=".MyApp"
      android:alwaysRetainTaskState="true"
      android:launchMode="singleInstance"
      android:theme="@style/MyMaterialTheme">
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="application/zip"/>
            </intent-filter>
</activity>

Now I'm calling this way to open the intent chooser

File downloadedfile = new File(Environment.getExternalStoragePublicDirectory(Environment.getExternalStorageDirectory() + "/myapp") + "/" + "downloadedfile.zip");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(downloadedfile), "application/zip");
startActivity(intent);

This works fine if I have ESFileExplorer has already installed on my app

But I would like to check if there is any pre-installed app is available or else I need to show playstore also as one of the option so that user can download the app and install the ESFileExplorer app.

So how do I do that ?

coder
  • 13,002
  • 31
  • 112
  • 214

2 Answers2

6

Android Intent Zip File

try{
    File downloadedfile = new File(Environment.getExternalStoragePublicDirectory(Environment.getExternalStorageDirectory() + "/myapp") + "/" + "downloadedfile.zip");
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(downloadedfile), "application/zip");
    startActivity(intent);
}catch (ActivityNotFoundException Ae){
    //When No application can perform zip file
    Uri uri = Uri.parse("market://search?q=" + "application/zip");
    Intent myAppLinkToMarket = new Intent(Intent.ACTION_VIEW, uri);

    try {
         startActivity(myAppLinkToMarket);
    } catch (ActivityNotFoundException e) {
         //the device hasn't installed Google Play
         Toast.makeText(MainActivity.this, "You don't have Google Play installed", Toast.LENGTH_LONG).show();
    }
}
Shabbir Dhangot
  • 8,954
  • 10
  • 58
  • 80
0

You can catch startActivity intent with ActivityNotFoundException and there you can launch ES File Explorer market app on play store.

maveroid
  • 1,840
  • 1
  • 20
  • 20