Search in sources :

Example 1 with DatabaseViewerActivity

use of com.amaze.filemanager.ui.activities.DatabaseViewerActivity in project AmazeFileManager by TeamAmaze.

the class FileUtils method openWith.

public static void openWith(final Uri uri, final PreferenceActivity activity, final boolean useNewStack) {
    MaterialDialog.Builder a = new MaterialDialog.Builder(activity);
    a.title(activity.getString(R.string.open_as));
    String[] items = new String[] { activity.getString(R.string.text), activity.getString(R.string.image), activity.getString(R.string.video), activity.getString(R.string.audio), activity.getString(R.string.database), activity.getString(R.string.other) };
    a.items(items).itemsCallback((materialDialog, view, i, charSequence) -> {
        String mimeType = null;
        Intent intent = null;
        switch(i) {
            case 0:
                mimeType = "text/*";
                break;
            case 1:
                mimeType = "image/*";
                break;
            case 2:
                mimeType = "video/*";
                break;
            case 3:
                mimeType = "audio/*";
                break;
            case 4:
                intent = new Intent(activity, DatabaseViewerActivity.class);
                intent.setAction(Intent.ACTION_VIEW);
                intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    intent.addFlags(Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS);
                }
                // DatabaseViewerActivity only accepts java.io.File paths, need to strip the URI
                // to file's absolute path
                intent.putExtra("path", uri.getPath().substring(uri.getPath().indexOf(FILE_PROVIDER_PREFIX) - 1, FILE_PROVIDER_PREFIX.length() + 1));
                break;
            case 5:
                mimeType = MimeTypes.getMimeType(uri.getPath(), false);
                if (mimeType == null)
                    mimeType = MimeTypes.ALL_MIME_TYPES;
                break;
        }
        try {
            if (intent != null) {
                activity.startActivity(intent);
            } else {
                OpenFileDialogFragment.Companion.openFileOrShow(uri, mimeType, useNewStack, activity, true);
            }
        } catch (Exception e) {
            Toast.makeText(activity, R.string.no_app_found, Toast.LENGTH_SHORT).show();
            openWith(uri, activity, useNewStack);
        }
    });
    a.build().show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DatabaseViewerActivity(com.amaze.filemanager.ui.activities.DatabaseViewerActivity) Intent(android.content.Intent) SFTPException(net.schmizz.sshj.sftp.SFTPException) ActivityNotFoundException(android.content.ActivityNotFoundException)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 DatabaseViewerActivity (com.amaze.filemanager.ui.activities.DatabaseViewerActivity)1 SFTPException (net.schmizz.sshj.sftp.SFTPException)1