But why would you want to directly insert data like that in the first place?

The SDK has a helper class, MediaScannerConnection, which submits a file 
for scanning, and makes sure it's properly indexed by the system. If you're 
going to use VIEW_ACTION, you can subclass and wait for the scan to 
complete.

On my Nexus 7 (last year's model) with 4.3, this whole thing takes all of 
100ms, probably less than the intent chooser's opening animation.

( I still think that making apps responsible for maintaining system level 
data structures was a weird decision... :) )

-- K

On Sunday, August 4, 2013 12:24:03 PM UTC+4, eli wrote:
>
> The solution for this issue is to query the Database, instead of insert to 
> it, I posted the full solution with code to this issue in my blog:
>
> http://androidwarzone.blogspot.co.il/2013/08/media-play-and-share-to-youtube-breaks.html
>
>
> Eli
>
>
> On Fri, Aug 2, 2013 at 11:20 PM, Eli Hasson <[email protected]<javascript:>
> > wrote:
>
>> Yep,
>> Looks like I found the issue:
>> 08-02 23:11:54.524: E/SQLiteDatabase(11214): Error inserting 
>> bucket_id=1643208667 media_type=3 title=out.mp4 storage_id=65537 
>> mime_type=video/mp4 date_modified=1375474313 _display_name=out.mp4 
>> date_added=1375474314 parent=1184 _size=325469 format=12299 
>> _data=/storage/emulated/0/compressed/out.mp4 bucket_display_name=compressed
>> 08-02 23:11:54.524: E/SQLiteDatabase(11214): 
>> android.database.sqlite.SQLiteConstraintException: column _data is not 
>> unique (code 19)
>>
>> The thing is, Google changed the functionality of the insert, seems that 
>> column data must be unique.
>>  
>> Eli
>>
>>
>> On Fri, Aug 2, 2013 at 11:02 PM, Nobu Games 
>> <[email protected]<javascript:>
>> > wrote:
>>
>>> Is there anything in log cat related to MediaStore?
>>>
>>>
>>> On Friday, August 2, 2013 2:43:17 PM UTC-5, eli wrote:
>>>
>>>> Thanks for your answer, I just entered hard coded values there to make 
>>>> the code more clear, this is not the issue.
>>>>
>>>> Eli
>>>> On Aug 2, 2013 10:29 PM, "Nobu Games" <[email protected]> wrote:
>>>>
>>>>> Sorry Eli,
>>>>>
>>>>> I should have read your code more carefully. You're hard-coding file 
>>>>> paths in that insert request which is bad practice. You cannot assume 
>>>>> that 
>>>>> there paths like "/sdcard/..." on all Android devices. They can be named 
>>>>> completely differently depending on device / manufacturer and especially 
>>>>> on 
>>>>> Jelly Bean there's  something like a "virtual file system" for supporting 
>>>>> multiple user accounts and these file paths look totally different.
>>>>>
>>>>> You should make use of the context.getExternalStorage(...**) and 
>>>>> related methods (also look into the Environment class).
>>>>>
>>>>> Maybe the hard-coded file path is the problem there?
>>>>>
>>>>> On Friday, August 2, 2013 2:20:50 PM UTC-5, eli wrote:
>>>>>>
>>>>>> It always return null on 4.3, and works perfectly on all other 
>>>>>> versions.
>>>>>> On Aug 2, 2013 10:13 PM, "Nobu Games" <[email protected]> wrote:
>>>>>>
>>>>>>> I just had a quick peek at the API level 14 source code and it looks 
>>>>>>> like there are two possible reasons for that problem:
>>>>>>>
>>>>>>> 1. The actual ContentProvider the ContentResolver connected to 
>>>>>>> returns null on insert (for whatever reason, that is a mystery)
>>>>>>> 2. A RemoteException was thrown during the insert operation. The 
>>>>>>> exception is caught by the ContentResolver and it returns just null 
>>>>>>> instead. The reason for that is (according to the source code comment) 
>>>>>>> that 
>>>>>>> the process / app is about to die anyway.
>>>>>>>
>>>>>>> Other ContentResolver methods behave exactly the same. Also the 
>>>>>>> query methods. It can - without a warning - just return null, even 
>>>>>>> though 
>>>>>>> it works in your tests a million times.
>>>>>>>
>>>>>>> You therefore need to check the result for null and come up with a 
>>>>>>> strategy for coping with that problem, like scheduling a re-query or 
>>>>>>> checking if your activity is about to be finished.
>>>>>>>
>>>>>>> On Friday, August 2, 2013 12:29:31 PM UTC-5, eli wrote:
>>>>>>>>
>>>>>>>> This code works on all Android versions except on 4.3:
>>>>>>>>
>>>>>>>>                            ContentValues content = new 
>>>>>>>> ContentValues(4);
>>>>>>>>             content.put(Video.**VideoColumn****s.TITLE, "vid.mp4");
>>>>>>>>             content.put(Video.**VideoColumn****s.DATE_ADDED,
>>>>>>>>             System.currentTimeMillis() / 1000);
>>>>>>>>             content.put(Video.Media.MIME_******TYPE, "video/mp4");
>>>>>>>>             content.put(MediaStore.Video.******Media.DATA, 
>>>>>>>> "/sdcard/vid.mp4");
>>>>>>>>             ContentResolver resolver = getContentResolver();
>>>>>>>>            * Uri uri = resolver.insert(MediaStore.Vid
>>>>>>>> eo.Media.EXTERNAL_CONTENT_URI,*
>>>>>>>> *            content);*
>>>>>>>>
>>>>>>>> On 4.3 *uri *is null.
>>>>>>>> Can someone help?
>>>>>>>>
>>>>>>>>  Thanks,
>>>>>>>> Eli
>>>>>>>>
>>>>>>>  -- 
>>>>>>> -- 
>>>>>>> You received this message because you are subscribed to the Google
>>>>>>> Groups "Android Developers" group.
>>>>>>> To post to this group, send email to android-d...@**googlegroups.com
>>>>>>> To unsubscribe from this group, send email to
>>>>>>> android-developers+**unsubscribe**@googlegroups.com
>>>>>>> For more options, visit this group at
>>>>>>> http://groups.google.com/**group**/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en>
>>>>>>> --- 
>>>>>>> You received this message because you are subscribed to a topic in 
>>>>>>> the Google Groups "Android Developers" group.
>>>>>>> To unsubscribe from this topic, visit https://groups.google.com/d/**
>>>>>>> to**pic/android-developers/I-**nzRB0**w6DM/unsubscribe<https://groups.google.com/d/topic/android-developers/I-nzRB0w6DM/unsubscribe>
>>>>>>> .
>>>>>>> To unsubscribe from this group and all its topics, send an email to 
>>>>>>> android-developers+**unsubscribe**@googlegroups.com.
>>>>>>> For more options, visit 
>>>>>>> https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out>
>>>>>>> .
>>>>>>>  
>>>>>>>  
>>>>>>>
>>>>>>  -- 
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Android Developers" group.
>>>>> To post to this group, send email to android-d...@**googlegroups.com
>>>>> To unsubscribe from this group, send email to
>>>>> android-developers+**[email protected]
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/**group/android-developers?hl=en<http://groups.google.com/group/android-developers?hl=en>
>>>>> --- 
>>>>> You received this message because you are subscribed to a topic in the 
>>>>> Google Groups "Android Developers" group.
>>>>> To unsubscribe from this topic, visit https://groups.google.com/d/**
>>>>> topic/android-developers/I-**nzRB0w6DM/unsubscribe<https://groups.google.com/d/topic/android-developers/I-nzRB0w6DM/unsubscribe>
>>>>> .
>>>>> To unsubscribe from this group and all its topics, send an email to 
>>>>> android-developers+**[email protected].
>>>>> For more options, visit 
>>>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>>>> .
>>>>>  
>>>>>  
>>>>>
>>>>  -- 
>>> -- 
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to 
>>> [email protected]<javascript:>
>>> To unsubscribe from this group, send email to
>>> [email protected] <javascript:>
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>> --- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Android Developers" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/android-developers/I-nzRB0w6DM/unsubscribe
>>> .
>>> To unsubscribe from this group and all its topics, send an email to 
>>> [email protected] <javascript:>.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to