Results 1 to 3 of 3

Thread: How to use QAndroidJniObject for intent.setData?

  1. #1
    Join Date
    Mar 2013
    Posts
    18
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default How to use QAndroidJniObject for intent.setData?

    Hi, I am looking for a way to update my android application manually. My idea is to start an activity/intent via androidextras module.
    I have tried following calls:

    Qt Code:
    1. QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;"); //activity is valid
    2. QAndroidJniObject path=QAndroidJniObject::fromString("file://mnt/sdcard/Download/QtApp.apk"); //path is valid
    3. QAndroidJniObject uri=QAndroidJniObject("java/net/URI","(Ljava/lang/String;)V",path.object<jstring>()); //uri is valid
    4. QAndroidJniObject intent("android/content/Intent","()V"); //intent is valid, but empty
    5. QAndroidJniObject type=QAndroidJniObject::fromString("application/vnd.android.package-archive"); //type is valid
    6. QAndroidJniObject result=intent.callObjectMethod("setType","(Ljava/lang/String;)Landroid/content/Intent;",type.object<jobject>()); //result is valid, intent contains type
    7. result=intent.callObjectMethod("setDataAndNormalize","(Ljava/net/URI;)Landroid/content/Intent;",uri.object<jobject>()); //result is invalid, intent contains type
    8. activity.callObjectMethod("startActivity","(Landroid/content/Intent;)V",intent.object<jobject>()); //works, but shows a selection screen for the intent containing email, bluetooth etc. because intent's data member is missing
    To copy to clipboard, switch view to plain text mode 

    Whenever I try to call setDataAndNormalize or even setData, result is always invalid and data member of intent is not set. Any clues what I am doing wrong?

  2. #2
    Join Date
    Mar 2013
    Posts
    18
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: How to use QAndroidJniObject for intent.setData?

    I have managed to create an intent with a dat member set this way:

    Qt Code:
    1. QAndroidJniObject path=QAndroidJniObject::fromString("file:///sdcard/Download/QtApp-debug.apk");
    2. QAndroidJniObject intent=QAndroidJniObject::QAndroidJniObject::callStaticObjectMethod("android/content/Intent","parseUri","(Ljava/lang/String;I)Landroid/content/Intent;",path.object<jstring>(),0x00000000);
    To copy to clipboard, switch view to plain text mode 

    Nevertheless when starting the activity, the application crashes

    Qt Code:
    1. W/Qt A11y (22001): EXCEPTION in dispatchHoverEvent for Accessibility: java.lang.reflect.InvocationTargetException
    2. W/Qt A11y (22001): EXCEPTION in dispatchHoverEvent for Accessibility: java.lang.reflect.InvocationTargetException
    3. W/Qt A11y (22001): EXCEPTION in dispatchHoverEvent for Accessibility: java.lang.reflect.InvocationTargetException
    4. W/dalvikvm(22001): Stack overflow on call to interp (req=76 top=0x402d5000 cur=0x402cf328 size=24576 Ljava/lang/reflect/Method;.<init>)
    5. W/Qt A11y (22001): EXCEPTION in dispatchHoverEvent for Accessibility: java.lang.reflect.InvocationTargetException
    6. E/Sensors ( 420): sensors_poll_context_t::pollEvents, line 202: receive event #### i=3, nb=1
    7. W/dalvikvm(22001): Invalid indirect reference 0x417b75d8 in decodeIndirectRef
    8. E/dalvikvm(22001): VM aborting
    9. F/libc (22001): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 22017 (.mcom4_facility)
    10. E/Trace (22045): error opening trace file: No such file or directory (2)
    11. W/dalvikvm(22045): Refusing to reopen boot DEX '/system/framework/hwframework.jar'
    To copy to clipboard, switch view to plain text mode 

    I found out that the newly created intent has no typ set (e.g. "application/vnd.android.package-archive").

  3. #3
    Join Date
    Sep 2011
    Posts
    14
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QAndroidJniObject for intent.setData?

    I know, I know ... the thread is not really all that fresh but it is one of the first things Google sent me to and it did give me a nice boost on solving the exact same issue so I figure I might save someone a few hours

    Qt Code:
    1. QAndroidJniObject path = QAndroidJniObject::fromString("file:///the-path-to-the-apk.apk");
    2. QAndroidJniObject uri = QAndroidJniObject::callStaticObjectMethod("android/net/Uri", "parse", "(Ljava/lang/String;)Landroid/net/Uri;", path.object<jstring>());
    3. QAndroidJniObject param = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "ACTION_VIEW");
    4. QAndroidJniObject intent("android/content/Intent","(Ljava/lang/String;)V",param.object<jstring>());
    5. QAndroidJniObject type = QAndroidJniObject::fromString("application/vnd.android.package-archive");
    6. QAndroidJniObject result = intent.callObjectMethod("setDataAndTypeAndNormalize", "(Landroid/net/Uri;Ljava/lang/String;)Landroid/content/Intent;", uri.object<jobject>(), type.object<jstring>());
    7. QtAndroid::startActivity(intent, 1001, 0);
    To copy to clipboard, switch view to plain text mode 

    You can obviously use any request code you wish and should check for exceptions but I believe the code to be self-explanatory enough. Tested and working on Qt 5.5.

Similar Threads

  1. necessitas: android intent & QProcess issues
    By tpf80 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 5th June 2015, 22:16
  2. Can’t create java class by QAndroidJniObject
    By stereoMatching in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 10th February 2014, 17:40
  3. QSqlTableModel and possible bug with setData?
    By sylvainb in forum Qt Programming
    Replies: 2
    Last Post: 25th February 2009, 21:43
  4. setData()
    By starcontrol in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2008, 08:54
  5. setData()
    By coderbob in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2008, 12:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.