简体   繁体   中英

No Activity found to handle intent { act=android.intent.action.PICK dat=[null, /storage/emulated/0/WhatsApp/Media/WhatsApp Video]

Am getting the error like this when I pass some path which has been stored in database.

在此处输入图片说明

Actually I am using the below code

ArrayList path_list;

 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
         uri = Uri.parse(path_list.get(2).toString());
        intent.setDataAndType(uri,"video/*");
        Log.e("URI",uri.toString());
        startActivityForResult(Intent.createChooser(intent, "Open folder"),152);

So please suggest whether I can use same code or have to change anything in this.

Databasehelper class

  public ArrayList<String> getpaths()
{
    ArrayList<String> path_list = new ArrayList<String>();

    //hp = new HashMap();
    SQLiteDatabase db = this.getReadableDatabase("somePass");
    Cursor res =  db.rawQuery( "select * from Configuration", null );
    res.moveToFirst();

    while(res.isAfterLast() == false){
        path_list.add(res.getString(res.getColumnIndex(COLUMN_NAME_VIDEOPATH)));
        res.moveToNext();
    }
    return path_list;
}

after open folder to get the selected path

 String selectedMediaPath = null;
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
                selectedMediaPath = getPath(this, uri);
                Log.e("path", path_list.get(2).toString());
                Log.d("mediapath",selectedMediaPath);
            }

This is the getpath() method:

 @RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static String getPath(final Context context, final Uri uri) {

    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }

            // TODO handle non-primary volumes
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(
                    Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] {
                    split[1]
            };

            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {
        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context The context.
 * @param uri The Uri to query.
 * @param selection (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 */
public static String getDataColumn(Context context, Uri uri, String selection,
                                   String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}


/**
 * @param uri The Uri to check.
 * @return Whether the Uri authority is ExternalStorageProvider.
 */
public static boolean isExternalStorageDocument(Uri uri) {
    return "com.android.externalstorage.documents".equals(uri.getAuthority());
}

/**
 * @param uri The Uri to check.
 * @return Whether the Uri authority is DownloadsProvider.
 */
public static boolean isDownloadsDocument(Uri uri) {
    return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}

/**
 * @param uri The Uri to check.
 * @return Whether the Uri authority is MediaProvider.
 */
public static boolean isMediaDocument(Uri uri) {
    return "com.android.providers.media.documents".equals(uri.getAuthority());
}

Log file:

10-19 15:30:24.549 12482-12482/com.onnurinet.andriodstb E/URI: /storage/emulated/0/WhatsApp/Media/WhatsApp Video

10-19 15:30:34.031 12482-12482/com.onnurinet.andriodstb E/uri: content://media/external/video/media/36930 10-19 15:30:34.050 12482-12482/com.onnurinet.andriodstb E/path: /storage/sdcard1/videos 10-19 15:30:34.050 12482-12482/com.onnurinet.andriodstb D/mediapath: /storage/emulated/0/WhatsApp/Media/WhatsApp Video/VID-20161018-WA0001.3gp 10-19 15:30:34.069 12482-12482/com.onnurinet.andriodstb D/intent path_list: /storage/sdcard1/videos 10-19 15:30:34.128 12482-12482/com.onnurinet.andriodstb D/url: /storage/sdcard1/videos

please tell something I tried for two days.

I think the error is very self explanatory. There isn't an app(actually activity) to handle the specific intent. Use

if (intent.resolveActivity(getPackageManager()) != null) {

    startAFR(intent);

}else{
    //Log no activity found
    //Inform user via toast/snackbar etc
}

Open Folder to pick a video file

Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
Uri uri = Uri.parse(...); 
intent.setDataAndType(uri, "video/*");   
startActivity(Intent.createChooser(intent, "Open folder"));

Whenever you are using ArrayList(path_list) you should get the values with it's index like path_list.get(0).toString();

 final Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
 intent.setData(Uri.parse(path_list.get(0).toString()));
 startActivityForResult(intent,152);

If you are having the problem still then try the below one

<activity android:name=".YourActivity">

    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="file" />
    <data android:mimeType="*/*" />
    <data android:pathPattern=".*\\.mp4" />

</activity>

And still you don't have a solution? then please try the below one

Open file securely with an external Android application without copying the file onto the external storage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM