i made two cursors imagecursor to get images sort by date time , Vcursor to get videos sort by date time .
but i need a single cursor to get both images and videos sort by date time .
i tried to merge those cursors to get new one , but it is not working as expected , newcursor is first going through all images and next all videos .
from kivy.utils import platform
if platform == "android":
from jnius import autoclass
from toast import Toast
thuu = autoclass('android.media.ThumbnailUtils')
pythonActivity = autoclass('org.kivy.android.PythonActivity')
ContentResolver = pythonActivity.mActivity
Jint = autoclass('java.lang.Integer')
Long = autoclass('java.lang.Long')
JString = autoclass('java.lang.String')
Context = autoclass('android.content.ContentResolver')
File = autoclass('java.io.File')
Uri = autoclass('android.net.Uri')
Cr = autoclass('android.content.ContentResolver')
def get__images(self) :
IMMedia = autoclass('android.provider.MediaStore$Images$Media')
print("images are loading ")
columns = [IMMedia.DATA, IMMedia._ID ] #;//get all columns of type images
orderBy = IMMedia.DATE_TAKEN #;//order data by date
imagecursor = ContentResolver.getContentResolver().query(
IMMedia.EXTERNAL_CONTENT_URI, columns, None ,
None , orderBy + " DESC") #;//get all data in Cursor by sorting in DESC order
imagecursor.moveToFirst()
i = 0
while not imagecursor.isAfterLast() :
print(i)
i = i + 1
dataColumnIndex = imagecursor.getColumnIndex(IMMedia.DATA) #;//get column index
print( imagecursor.getString(dataColumnIndex) ) #;//get Image from column index
imagecursor.moveToNext()
print("++++++")
print( imagecursor.getCount() )
print(i)
print("=====================================================================================================")
self.get__videos(i , imagecursor )
def get__videos(self , i , imagecursor ) :
VMedia = autoclass('android.provider.MediaStore$Video$Media') # similarly for videos .
print("images are loading ")
columns = [VMedia.DATA, VMedia._ID ] #;//get all columns of type images
orderBy = VMedia.DATE_TAKEN #;//order data by date
Vcursor = ContentResolver.getContentResolver().query(
VMedia.EXTERNAL_CONTENT_URI, columns, None ,
None , orderBy + " DESC") #;//get all data in Cursor by sorting in DESC order
Vcursor.moveToFirst()
v = 0
while not Vcursor.isAfterLast() :
print(v)
v = v + 1
dataColumnIndex = Vcursor.getColumnIndex(VMedia.DATA) #;//get column index
print( Vcursor.getString(dataColumnIndex) ) #;//get Image from column index
Vcursor.moveToNext()
print("++++++")
print( Vcursor.getCount() )
print(v)
print(i + v , " <<< i and v ")
MergeCursor = autoclass('android.database.MergeCursor')
newcursor = MergeCursor([imagecursor , Vcursor ])
newcursor.moveToFirst()
t = 0
while not newcursor.isAfterLast() :
print(t)
t = t + 1
dataColumnIndex = newcursor.getColumnIndex(VMedia.DATA) #;//get column index
print( newcursor.getString(dataColumnIndex) ) #;//get Image from column index
newcursor.moveToNext()
print("++++++")
print( newcursor.getCount() )
print( t , " <<< t ")
print(i + v , " <<< i and v ")