嘿,我正在尝试开发一款允许用户分享视频文件的应用。 每当我第二次尝试共享同一个视频文件时,我都会遇到约束失败错误
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)
当我第一次尝试共享视频时,它总是有效,只有当我尝试在同一个文件上多次执行时才会发生这种情况。 它通过蓝牙共享工作正常只有当我尝试使用youtube或facebook应用程序共享时它才会失败。这是我的颂歌共享部分。
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:"));
}
});
只是为了澄清我知道视频在那里,只有在我尝试多次失败时它才能正常工作(在应用程序中它只显示错误发生且youtube应用程序崩溃)。 先谢谢你们。