【问题标题】:No Activity found to handle intent { act=android.intent.action.PICK dat=[null, /storage/emulated/0/WhatsApp/Media/WhatsApp Video]未找到处理意图的活动 { act=android.intent.action.PICK dat=[null, /storage/emulated/0/WhatsApp/Media/WhatsApp Video]
【发布时间】:2016-10-19 05:11:01
【问题描述】:

当我传递一些已存储在数据库中的路径时,我收到这样的错误。

其实我用的是下面的代码

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);

所以请建议我是否可以使用相同的代码或必须更改其中的任何内容。

数据库助手类

  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;
}

打开文件夹后得到选择的路径

 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);
            }

这是 getpath() 方法:

 @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());
}

日志文件:

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/路径:/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

请说说我这两天试过的东西。

【问题讨论】:

  • 设备中是否安装了whatsapp?
  • 是的,当我点击它时它就在那里,它必须转到那个 whatsappvideo 所在的画廊路径

标签: android


【解决方案1】:

我认为这个错误是不言自明的。没有应用程序(实际上是活动)来处理特定意图。 使用

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

    startAFR(intent);

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

打开文件夹选择视频文件

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

【讨论】:

  • 这意味着没有活动可以处理您的特定Intent
  • 当我使用你的代码时什么都没有发生没有崩溃没有输出
  • 是的,如果没有应用程序可以处理 Intent,这将是所需的输出。见编辑。
  • 我们可以使用任何东西来代替 startAFR() 来打开那个 URL
  • 那将是 intent.setAction(Intent.ACTION_VIEW)intent.setType("video/*"/*for video*/) 然后是 intent.setData(Uri.parse(path_list.get(0).toString()));
【解决方案2】:

每当您使用 ArrayList(path_list) 时,您都应该使用它的索引获取值,例如 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);

如果您仍然遇到问题,请尝试以下方法

<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>

你还没有解决办法吗?那么请尝试下面的一个

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

【讨论】:

  • 我已经用两个可能的来源编辑了我的答案来解决您的问题,如果您遇到问题,请告诉我。
  • 根据@Elvis Chweya 没有同样的问题无法打开存储在数组列表中的路径
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多