我正在尝试在android文件选择器上多选文件,但它返回None。我认为错误来自第29行。如果你想要uri但代码可以工作,但是我需要一个kivy图像小部件或声音加载器的文件路径。任何帮助将不胜感激,因为我愿意学习。谢谢!
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)