Java - Android multi-file chooser on kivy. Python

131 views
Skip to first unread message

Ish Rash

unread,
May 21, 2018, 11:34:51 PM5/21/18
to Kivy users support
I'm trying to multi-select files on android file chooser, but it returns None. I think the error is from line 29. The code works if your want the Uri but I need the filepath for a kivy image widget or soundloader. Any help will be appreciated because I'm willing to learn. Thank you!

def select_media(self, callback, mood):
    type0
= ''
   
if 'image' in mood: type0 = "image/*"
   
if 'audio' in mood: type0 = "audio/*"
   
if 'vid' in mood: type0 = "video/*"

    currentActivity
= cast('android.app.Activity', PythonActivity.mActivity)

   
def on_activity_result(request_code, result_code, intent):
       
if request_code != RESULT_LOAD_IMAGE:
           
Logger.warning('select_media: ignoring activity result that was not RESULT_LOAD_IMAGE')
           
return

       
if result_code == Activity.RESULT_CANCELED:
           
Clock.schedule_once(lambda dt: callback(None), 0)
           
return

       
if result_code != Activity.RESULT_OK:
           
raise NotImplementedError('Unknown result_code "{}"'.format(result_code))
       
self.multi_imgs = []

        mClipData
= intent.getClipData();
        list0
= [];
       
for i in range(0, mClipData.getItemCount()):
            item
= mClipData.getItemAt(i);
            uri
= item.getUri();
            list0
.append(uri);
            filePathColumn
= [MediaStore_Images_Media_DATA];
            cursor
= currentActivity.getContentResolver().query(uri,
                    filePathColumn
, None, None, None);
            cursor
.moveToFirst();
            columnIndex
= cursor.getColumnIndex(filePathColumn[0]);
            itemPath  
= cursor.getString(columnIndex);
           
self.multi_imgs.append(itemPath);
            cursor
.close();
           
Clock.schedule_once(lambda dt: callback(itemPath), 0)
       
self.selected_images = self.multi_imgs

    activity
.bind(on_activity_result=on_activity_result)
    intent
= Intent()

    intent
.setAction(Intent.ACTION_GET_CONTENT)
 
#   intent.setData(Uri.parse('content://media/internal/images/media'))
    intent
.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, True)
    intent
.setType(type0)
    currentActivity
.startActivityForResult(intent, RESULT_LOAD_IMAGE)
 
#  chooser = Intent.createChooser(intent,String("Select Picture"))
 
#  currentActivity.startActivityForResult(chooser, RESULT_LOAD_IMAGE)


Sadaka Technology

unread,
Oct 10, 2020, 2:43:45 PM10/10/20
to Kivy users support
@I.R.B.A Hey there, I believe this is a related code for uploading image or video from phone to app like in this link (https://www.youtube.com/watch?v=MkKHqX44Mv8) do you have a link describing the whole code?! or I can understand from!
Reply all
Reply to author
Forward
0 new messages