2016-08-16 6 views
3

이미지 공유에 안드로이드 ACTION_SEND 의도를 사용할 공유 버튼을 만들고 싶습니다. 그것은이 라인 shareIntent.putExtra(Intent.EXTRA_STREAM, uri)이 오류 jnius.jnius.JavaException: Invalid instance of u'android/net/Uri' passed for a u'java/lang/String'를 throw)kivy 안드로이드 공유 이미지

from kivy.setupconfig import USE_SDL2 


def share(path): 
    if platform == 'android': 
     from jnius import cast 
     from jnius import autoclass 
     if USE_SDL2: 
      PythonActivity = autoclass('org.kivy.android.PythonActivity') 
     else: 
      PythonActivity = autoclass('org.renpy.android.PythonActivity') 
     Intent = autoclass('android.content.Intent') 
     String = autoclass('java.lang.String') 
     Uri = autoclass('android.net.Uri') 
     File = autoclass('java.io.File') 

     shareIntent = Intent(Intent.ACTION_SEND) 
     shareIntent.setType('"image/*"') 
     imageFile = File(path) 
     uri = Uri.fromFile(imageFile) 
     shareIntent.putExtra(Intent.EXTRA_STREAM, uri) 

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

그러나 그것은 작동하지 않습니다 : 그것은 내 코드입니다. 이 문제를 어떻게 해결할 수 있습니까?

답변

2

해결책을 찾았습니다. 당신은 uri를 분해 할 수 있도록 던져야하고, 의도에 따라야합니다 :

parcelable = cast('android.os.Parcelable', uri) 
shareIntent.putExtra(Intent.EXTRA_STREAM, parcelable)