mirror of
https://gitee.com/shuto/cordova-plugin-file-opener2.git
synced 2025-01-31 03:52:51 +08:00
Merge pull request #274 from cinthiaro/master
Open file in Android when the mime type is not specified
This commit is contained in:
commit
dac2053dfe
@ -35,6 +35,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import io.github.pwlin.cordova.plugins.fileopener2.FileProvider;
|
||||
|
||||
@ -102,6 +103,10 @@ public class FileOpener2 extends CordovaPlugin {
|
||||
File file = new File(fileName);
|
||||
if (file.exists()) {
|
||||
try {
|
||||
if (contentType == null || contentType.trim().equals("")) {
|
||||
contentType = _getMimeType(fileName);
|
||||
}
|
||||
|
||||
Intent intent;
|
||||
if (contentType.equals("application/vnd.android.package-archive")) {
|
||||
// https://stackoverflow.com/questions/9637629/can-we-install-an-apk-from-a-contentprovider/9672282#9672282
|
||||
@ -151,6 +156,18 @@ public class FileOpener2 extends CordovaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private String _getMimeType(String url) {
|
||||
String mimeType = "*/*";
|
||||
int extensionIndex = url.lastIndexOf('.');
|
||||
if (extensionIndex > 0) {
|
||||
String extMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(url.substring(extensionIndex+1));
|
||||
if (extMimeType != null) {
|
||||
mimeType = extMimeType;
|
||||
}
|
||||
}
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
private void _uninstall(String packageId, CallbackContext callbackContext) throws JSONException {
|
||||
if (this._appIsInstalled(packageId)) {
|
||||
Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE);
|
||||
|
Loading…
Reference in New Issue
Block a user