UNIQUE constraint failed when trying to share video via intent

此生再无相见时 提交于 2019-12-08 07:28:28

问题


Hey I'm trying to develop an app which would allow users to share video files. Whenever I try to share the same video file for the second time I get constraint failed error

11-21 20:46:47.103    1076-4528/? E/SQLiteDatabase﹕ Error inserting bucket_id=-1634214109 date_modified=1448138795 datetaken=1448138795000 bucket_display_name=.estrongs parent=894 format=12299 storage_id=131073 media_type=3 mime_type=video/mp4 _size=1235266 title=video1 _data=/storage/sdcard1/.estrongs/video1.mp4 date_added=1448138807 _display_name=video1.mp4
android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: files._data (code 2067)
        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782)
        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
        at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1471)
        at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
        at com.android.providers.media.MediaProvider.insertFile(MediaProvider.java:3303)
        at com.android.providers.media.MediaProvider.insertInternal(MediaProvider.java:3621)
        at com.android.providers.media.MediaProvider.insert(MediaProvider.java:2955)
        at android.content.ContentProvider$Transport.insert(ContentProvider.java:235)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:163)
        at android.os.Binder.execTransact(Binder.java:446)

It always works when I try to share video for the first time, it only happens when I try to do more than once on the same file. It works fine with sharing via bluetooth it only fails when I try to share using youtube or facebook application. Here is my ode which does the sharing part.

        MediaScannerConnection.scanFile(getActivity(), new String[]{recordings.get(viewNumber).getDirectory() + "/" + recordings.get(viewNumber).getFilename() + ".mp4"}, null,
            new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {
                    recordings.get(viewNumber).setUploaded(true);
                    ContentValues content = new ContentValues(4);
                    content.put(MediaStore.Video.VideoColumns.DATE_ADDED,
                            System.currentTimeMillis());
                    content.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
                    content.put(MediaStore.Video.Media.DATA, recordings.get(viewNumber).getDirectory() + "/" + recordings.get(viewNumber).getFilename() + ".mp4");
                    ContentResolver resolver = getActivity().getBaseContext().getContentResolver();
                    uri = resolver.insert(MediaStore.Video.Media.INTERNAL_CONTENT_URI, content);

                    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
                    sharingIntent.setType("video/*");
                    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Title");
                    sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri);
                    startActivity(Intent.createChooser(sharingIntent, "Share:"));
                }
            });

Just to clarify I know the video is there, it works fine when shared for the first time only when I try to do it more than once it fails(In apps it only says Error occurred and the youtube application crashes). Thanks in advance guys.

来源:https://stackoverflow.com/questions/33848511/unique-constraint-failed-when-trying-to-share-video-via-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!