summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/Settings_Authentication.java2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/Utils.java24
-rw-r--r--main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java2
-rw-r--r--main/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java2
4 files changed, 26 insertions, 4 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Authentication.java b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Authentication.java
index 236d7947..834ec82b 100644
--- a/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Authentication.java
+++ b/main/src/main/java/de/blinkt/openvpn/fragments/Settings_Authentication.java
@@ -165,7 +165,7 @@ public class Settings_Authentication extends OpenVpnPreferencesFragment implemen
void startFileDialog() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- Intent startFC = Utils.getFilePickerIntent (Utils.FileType.TLS_AUTH_FILE);
+ Intent startFC = Utils.getFilePickerIntent (getActivity(), Utils.FileType.TLS_AUTH_FILE);
startActivityForResult(startFC, SELECT_TLS_FILE_KITKAT);
} else {
Intent startFC = new Intent(getActivity(), FileSelect.class);
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/Utils.java b/main/src/main/java/de/blinkt/openvpn/fragments/Utils.java
index bb35a517..b4ba476b 100644
--- a/main/src/main/java/de/blinkt/openvpn/fragments/Utils.java
+++ b/main/src/main/java/de/blinkt/openvpn/fragments/Utils.java
@@ -3,6 +3,8 @@ package de.blinkt.openvpn.fragments;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
@@ -14,12 +16,13 @@ import de.blinkt.openvpn.VpnProfile;
import junit.framework.Assert;
import java.io.*;
+import java.util.List;
import java.util.TreeSet;
import java.util.Vector;
public class Utils {
- public static Intent getFilePickerIntent(FileType fileType) {
+ public static Intent getFilePickerIntent(Context c, FileType fileType) {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE);
TreeSet<String> supportedMimeTypes = new TreeSet<String>();
@@ -93,9 +96,28 @@ public class Utils {
supportedMimeTypes.add("application/octet-stream");
i.putExtra(Intent.EXTRA_MIME_TYPES, supportedMimeTypes.toArray(new String[supportedMimeTypes.size()]));
+
+
+ /* Samsung has decided to do something strange, on stock Android GET_CONTENT opens the document UI */
+ /* fist try with documentsui */
+ i.setPackage("com.android.documentsui");
+
+ if (!isIntentAvailable(c,i)) {
+ i.setAction(Intent.ACTION_OPEN_DOCUMENT);
+ i.setPackage(null);
+ }
+
return i;
}
+
+ public static boolean isIntentAvailable(Context context, Intent i) {
+ final PackageManager packageManager = context.getPackageManager();
+ List<ResolveInfo> list =
+ packageManager.queryIntentActivities(i,
+ PackageManager.MATCH_DEFAULT_ONLY);
+ return list.size() > 0;
+ }
public enum FileType {
PKCS12(0),
CLIENT_CERTIFICATE(1),
diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java b/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java
index b26f3505..693a7e71 100644
--- a/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java
+++ b/main/src/main/java/de/blinkt/openvpn/fragments/VPNProfileList.java
@@ -220,7 +220,7 @@ public class VPNProfileList extends ListFragment {
@TargetApi(Build.VERSION_CODES.KITKAT)
private void startFilePicker() {
- Intent i = Utils.getFilePickerIntent(Utils.FileType.OVPN_CONFIG);
+ Intent i = Utils.getFilePickerIntent(getActivity(), Utils.FileType.OVPN_CONFIG);
startActivityForResult(i, FILE_PICKER_RESULT);
}
diff --git a/main/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java b/main/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java
index 362777e4..e2affe93 100644
--- a/main/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java
+++ b/main/src/main/java/de/blinkt/openvpn/views/FileSelectLayout.java
@@ -138,7 +138,7 @@ public class FileSelectLayout extends LinearLayout implements OnClickListener {
public void onClick(View v) {
if (v == mSelectButton) {
if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
- Intent startFilePicker = Utils.getFilePickerIntent(fileType);
+ Intent startFilePicker = Utils.getFilePickerIntent(getContext(),fileType);
mFragment.startActivityForResult(startFilePicker, mTaskId);
} else {
getCertificateFileDialog();