aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2013-09-19 02:02:51 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2013-09-19 02:02:51 +0200
commit3c4cb1c2d31ff472dc09d4f71f3f5e9af7547cdd (patch)
treed8d7ad9ea2b8fac8c988ec38885d4645242c5168 /OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper
parent4c461c1b445eb339382b5ffd174e6d19b93f25d0 (diff)
downloadopen-keychain-3c4cb1c2d31ff472dc09d4f71f3f5e9af7547cdd.tar.gz
open-keychain-3c4cb1c2d31ff472dc09d4f71f3f5e9af7547cdd.tar.bz2
open-keychain-3c4cb1c2d31ff472dc09d4f71f3f5e9af7547cdd.zip
Work on new Import activity
Diffstat (limited to 'OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper')
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/FileHelper.java33
1 files changed, 26 insertions, 7 deletions
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/FileHelper.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/FileHelper.java
index 115e0e36d..acb7f71f8 100644
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/FileHelper.java
+++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/helper/FileHelper.java
@@ -28,6 +28,7 @@ import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
+import android.support.v4.app.Fragment;
import android.widget.Toast;
public class FileHelper {
@@ -55,18 +56,14 @@ public class FileHelper {
* @param activity
* @param filename
* default selected file, not supported by all file managers
- * @param type
+ * @param mimeType
* can be text/plain for example
* @param requestCode
* requestCode used to identify the result coming back from file manager to
* onActivityResult() in your activity
*/
- public static void openFile(Activity activity, String filename, String type, int requestCode) {
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
- intent.addCategory(Intent.CATEGORY_OPENABLE);
-
- intent.setData(Uri.parse("file://" + filename));
- intent.setType(type);
+ public static void openFile(Activity activity, String filename, String mimeType, int requestCode) {
+ Intent intent = buildFileIntent(filename, mimeType);
try {
activity.startActivityForResult(intent, requestCode);
@@ -76,6 +73,28 @@ public class FileHelper {
}
}
+ public static void openFile(Fragment fragment, String filename, String mimeType, int requestCode) {
+ Intent intent = buildFileIntent(filename, mimeType);
+
+ try {
+ fragment.startActivityForResult(intent, requestCode);
+ } catch (ActivityNotFoundException e) {
+ // No compatible file manager was found.
+ Toast.makeText(fragment.getActivity(), R.string.noFilemanagerInstalled,
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ private static Intent buildFileIntent(String filename, String mimeType) {
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
+
+ intent.setData(Uri.parse("file://" + filename));
+ intent.setType(mimeType);
+
+ return intent;
+ }
+
/**
* Get a file path from a Uri.
*