Kivy: [WindowSDL] No running App found, exit

218 Views Asked by At

iam doing image chooser in kivy from gallery by using jnius with intents Then i click button it opening gallery and the app is closing in logcat i got

05-07 15:27:19.507 30865 30865 I python : [INFO ] [WindowSDL ] No running App found, exit. 05-07 15:27:19.508 30865 30865 I python : [INFO ] [Base ] Leaving application in progress... 05-07 15:27:19.514 30865 30923 I python : [INFO ] [WindowSDL ] exiting mainloop and closing.

05-07 15:27:19.570 30865 30923 I python : Traceback (most recent call last): 05-07 15:27:19.570 30865 30923 I python : File "/content/.buildozer/android/app/main.py", line 103, in

05-07 15:27:19.571 30865 30923 I python : AttributeError: 'NoneType' object has no attribute 'run'

05-07 15:27:19.571 30865 30923 I python : Python for android ended. here is my code:-

from android.runnable import run_on_ui_thread as run_thread
from jnius import autoclass, cast
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.app import runTouchApp
from kivy.clock import Clock, mainthread
from android import activity as act
    
m=GridLayout(cols=1,rows=1)
d=GridLayout(cols=1,rows=1)
m.add_widget(d)
Uri = autoclass('android.net.Uri')

# Value of MediaStore.Images.Media.DATA
MediaStore_Images_Media_DATA = "_data"

# Custom request codes
RESULT_LOAD_IMAGE = 1
PythonActivity = autoclass('org.kivy.android.PythonActivity')
WebViewA = autoclass('android.webkit.WebView')
Intent = autoclass('android.content.Intent')
Activity = autoclass('android.app.Activity')
WebViewClient = autoclass('android.webkit.WebViewClient')
LinearLayout = autoclass('android.widget.LinearLayout')
Context = autoclass('android.content.Context')
Uri = autoclass('android.net.Uri')
ViewGroup = autoclass('android.view.ViewGroup')
LayoutParams = autoclass('android.view.ViewGroup$LayoutParams')
# Activity is only used to get these codes. Could just hardcode them.
    # /** Standard activity result: operation canceled. */
    # public static final int RESULT_CANCELED    = 0;
    # /** Standard activity result: operation succeeded. */
    # public static final int RESULT_OK           = -1;
    # /** Start of user-defined activity results. */
    # Not sure what this means
    # public static final int RESULT_FIRST_USER   = 1;
@run_thread
def Push(callback):
    """Open Gallery Activity and call callback with absolute image filepath of image user selected.
    None if user canceled.
    """
    activity1 = cast('android.app.Activity', PythonActivity.mActivity)
    # PythonActivity.mActivity is the instance of the current Activity
    # BUT, startActivity is a method from the Activity class, not from our
    # PythonActivity.
    # We need to cast our class into an activity and use it
    # Forum discussion: https://groups.google.com/forum/#!msg/kivy-users/bjsG2j9bptI/-Oe_aGo0newJ
    def on_activity_result(request_code, result_code, intent):
        if request_code != RESULT_LOAD_IMAGE:
            print("not selected")
            return

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

        if result_code != Activity.RESULT_OK:
            # This may just go into the void...
            raise NotImplementedError('Unknown result_code "{}"'.format(result_code))

        selectedImage = intent.getData() # Uri
        filePathColumn = [MediaStore_Images_Media_DATA] # String[]
        # Cursor
        cursor = currentActivity.getContentResolver().query(selectedImage,
                filePathColumn, None, None, None)
        cursor.moveToFirst()

        # int
        columnIndex = cursor.getColumnIndex(filePathColumn[0])
        # String
        picturePath = cursor.getString(columnIndex)
        cursor.close()
        print('android_ui: user_select_image() selected '+picturePath)
        parent = cast(ViewGroup, layout.getParent())
        if parent is not None:parent.removeView(layout)
        webview.clearHistory()
        webview.clearCache(True)
        webview.clearFormData()
        webview.destroy()
        layout = None
        webview = None


    # See: http://pyjnius.readthedocs.org/en/latest/android.html
    act.bind(on_activity_result=on_activity_result)

    intent= Intent(Intent.ACTION_GET_CONTENT)
    intent.addCategory(Intent.CATEGORY_OPENABLE)
    intent.setType("image/*")
    intent.setAction(Intent.ACTION_GET_CONTENT)
    

    # http://programmerguru.com/android-tutorial/how-to-pick-image-from-gallery/
    # http://stackoverflow.com/questions/18416122/open-gallery-app-in-android

    # TODO setType(Image)?
    activity1.startActivityForResult(intent, RESULT_LOAD_IMAGE)
b=Button(text="hi")
b.bind(on_press=Push)
d.add_widget(b)
runTouchApp(m)

thanks in advance

1

There are 1 best solutions below

0
On BEST ANSWER

After adding classes and changing it to App().run() it works fine by the comment above thanks