Qt for Android - startActivityForResult 等效项不起作用
Posted
技术标签:
【中文标题】Qt for Android - startActivityForResult 等效项不起作用【英文标题】:Qt for Android - startActivityForResult equivalent does not work 【发布时间】:2015-05-23 10:36:13 【问题描述】:Qt for android 中的功能文档很少——我们可以通过 JNI(Java 原生接口)使用 Intent 功能。有一些与 startActivity 等效的示例,但我没有找到任何与结果接收有关的示例。
这是我想要做的说明的 Java 代码:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
getActivity().startActivityForResult(intent, 1);
我使用文档在 Qt 中编写了等价物:
QAndroidJniObject ACTION_GET_CONTENT = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "ACTION_GET_CONTENT");
QAndroidJniObject intent("android/content/Intent");
if (ACTION_GET_CONTENT.isValid() && intent.isValid())
intent.callObjectMethod("setAction", "(Ljava/lang/string;)V", ACTION_GET_CONTENT.object<jstring>());
intent.callObjectMethod("setType", "(Ljava/lang/string;)V", QAndroidJniObject::fromString("file/*").object<jstring>());
QtAndroid::startActivity(intent, EXISTING_FILE_NAME_REQUEST, receiver);
return true;
else
return false;
receiver 是一个指向类对象的指针,它扩展了抽象类 QAndroidActivityResultReceiver。下面是虚函数handleActivityResult的实现:
void MyReceiver::handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data)
jint RESULT_OK = QAndroidJniObject::getStaticField<jint>("android/app/Activity", "RESULT_OK");
if (receiverRequestCode == EXISTING_FILE_NAME_REQUEST && resultCode == RESULT_OK)
QString path = data.callObjectMethod("getData", "()Landroid/net/Uri;").callObjectMethod("getPath", "()Ljava/lang/String;").toString();
_dialog->emitExistingFileNameReady(path);
else
_dialog->emitExistingFileNameReady(QString());
我的代码有问题,因为当我运行它时,会出现以下错误消息(并且程序正在中止):
F/art ( 6837): art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception 'android.content.ActivityNotFoundException' thrown in unknown throw location
F/art ( 6837): art/runtime/check_jni.cc:65] in call to NewGlobalRef
F/art ( 6837): art/runtime/check_jni.cc:65] "QtThread" prio=5 tid=15 Runnable
F/art ( 6837): art/runtime/check_jni.cc:65] | group="main" sCount=0 dsCount=0 obj=0x12e75100 self=0xaec43400
F/art ( 6837): art/runtime/check_jni.cc:65] | sysTid=6882 nice=0 cgrp=default sched=0/0 handle=0xb491b780
F/art ( 6837): art/runtime/check_jni.cc:65] | state=R schedstat=( 0 0 0 ) utm=39 stm=20 core=0 HZ=100
F/art ( 6837): art/runtime/check_jni.cc:65] | stack=0xa2b04000-0xa2b06000 stackSize=1012KB
F/art ( 6837): art/runtime/check_jni.cc:65] | held mutexes= "mutator lock"(shared held)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #00 pc 00004e64 /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #01 pc 00003665 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #02 pc 00256429 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+84)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #03 pc 00238fe7 /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+158)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #04 pc 000b191b /system/lib/libart.so (art::JniAbort(char const*, char const*)+610)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #05 pc 000b2055 /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+68)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #06 pc 000b530f /system/lib/libart.so (art::ScopedCheck::ScopedCheck(_JNIEnv*, int, char const*)+1346)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #07 pc 000b66cd /system/lib/libart.so (art::CheckJNI::NewGlobalRef(_JNIEnv*, _jobject*)+28)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #08 pc 001ea0a7 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QJNIObjectPrivate::QJNIObjectPrivate(_jobject*)+82)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #09 pc 001ea69d /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (???)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #10 pc 001ec719 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QJNIObjectPrivate::getStaticObjectField(char const*, char const*, char const*)+48)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #11 pc 0017718d /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (???)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #12 pc 00177a3d /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QStandardPaths::writableLocation(QStandardPaths::StandardLocation)+860)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #13 pc 0017841f /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QStandardPaths::standardLocations(QStandardPaths::StandardLocation)+790)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #14 pc 00013e5b /data/app/org.qtproject.example.TouchImage-2/lib/arm/libTouchImage.so (ApplicationController::openFileButtonClicked()+130)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #15 pc 001cce4f /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QMetaObject::activate(QObject*, int, int, void**)+394)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #16 pc 00261987 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QAbstractButton::clicked(bool)+26)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #17 pc 001460f9 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (???)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #18 pc 001468f7 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (???)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #19 pc 00146979 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QAbstractButton::mouseReleaseEvent(QMouseEvent*)+88)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #20 pc 0019d509 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QToolButton::mouseReleaseEvent(QMouseEvent*)+4)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #21 pc 00100bbd /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QWidget::event(QEvent*)+536)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #22 pc 0019d57d /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QToolButton::event(QEvent*)+50)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #23 pc 000e2a41 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QApplicationPrivate::notify_helper(QObject*, QEvent*)+104)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #24 pc 000e5583 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QApplication::notify(QObject*, QEvent*)+1382)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #25 pc 001ae40f /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QCoreApplication::notifyInternal(QObject*, QEvent*)+62)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #26 pc 000e4d5b /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool)+286)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #27 pc 0010a19b /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (???)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #28 pc 0010a8d3 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (???)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #29 pc 000e2a41 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QApplicationPrivate::notify_helper(QObject*, QEvent*)+104)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #30 pc 000e5e53 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QApplication::notify(QObject*, QEvent*)+3638)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #31 pc 001ae40f /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QCoreApplication::notifyInternal(QObject*, QEvent*)+62)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #32 pc 000a09cd /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Gui.so (QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*)+516)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #33 pc 000a06ed /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Gui.so (QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent*)+3492)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #34 pc 000a1b13 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Gui.so (QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*)+382)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #35 pc 00093181 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Gui.so (QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>)+20)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #36 pc 00028135 /data/data/org.qtproject.example.TouchImage/qt-reserved-files/plugins/platforms/android/libqtforandroid.so (???)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #37 pc 001ad533 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)+14)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #38 pc 001adc13 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)+226)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #39 pc 001b2527 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QCoreApplication::exec()+82)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #40 pc 00012a41 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libTouchImage.so (main+48)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #41 pc 000190b5 /data/data/org.qtproject.example.TouchImage/qt-reserved-files/plugins/platforms/android/libqtforandroid.so (???)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #42 pc 00016baf /system/lib/libc.so (__pthread_start(void*)+30)
F/art ( 6837): art/runtime/check_jni.cc:65] native: #43 pc 00014af3 /system/lib/libc.so (__start_thread+6)
F/art ( 6837): art/runtime/check_jni.cc:65] (no managed stack frames)
F/art ( 6837): art/runtime/check_jni.cc:65]
F/art ( 6837): art/runtime/runtime.cc:289] Runtime aborting...
F/art ( 6837): art/runtime/runtime.cc:289] Aborting thread:
F/art ( 6837): art/runtime/runtime.cc:289] "QtThread" prio=5 tid=15 Native
F/art ( 6837): art/runtime/runtime.cc:289] | group="" sCount=0 dsCount=0 obj=0x12e75100 self=0xaec43400
F/art ( 6837): art/runtime/runtime.cc:289] | sysTid=6882 nice=0 cgrp=default sched=0/0 handle=0xb491b780
F/art ( 6837): art/runtime/runtime.cc:289] | state=R schedstat=( 0 0 0 ) utm=42 stm=20 core=0 HZ=100
F/art ( 6837): art/runtime/runtime.cc:289] | stack=0xa2b04000-0xa2b06000 stackSize=1012KB
F/art ( 6837): art/runtime/runtime.cc:289] | held mutexes= "abort lock" "mutator lock"(shared held)
F/art ( 6837): art/runtime/runtime.cc:289] native: #00 pc 00004e64 /system/lib/libbacktrace_libc++.so (UnwindCurrent::Unwind(unsigned int, ucontext*)+23)
F/art ( 6837): art/runtime/runtime.cc:289] native: #01 pc 00003665 /system/lib/libbacktrace_libc++.so (Backtrace::Unwind(unsigned int, ucontext*)+8)
F/art ( 6837): art/runtime/runtime.cc:289] native: #02 pc 00256429 /system/lib/libart.so (art::DumpNativeStack(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, int, char const*, art::mirror::ArtMethod*)+84)
F/art ( 6837): art/runtime/runtime.cc:289] native: #03 pc 00238fe7 /system/lib/libart.so (art::Thread::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const+158)
F/art ( 6837): art/runtime/runtime.cc:289] native: #04 pc 0022881d /system/lib/libart.so (art::AbortState::DumpThread(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, art::Thread*)+32)
F/art ( 6837): art/runtime/runtime.cc:289] native: #05 pc 00228abf /system/lib/libart.so (art::AbortState::Dump(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)+410)
F/art ( 6837): art/runtime/runtime.cc:289] native: #06 pc 00228c7f /system/lib/libart.so (art::Runtime::Abort()+82)
F/art ( 6837): art/runtime/runtime.cc:289] native: #07 pc 000a7371 /system/lib/libart.so (art::LogMessage::~LogMessage()+1360)
F/art ( 6837): art/runtime/runtime.cc:289] native: #08 pc 000b1b17 /system/lib/libart.so (art::JniAbort(char const*, char const*)+1118)
F/art ( 6837): art/runtime/runtime.cc:289] native: #09 pc 000b2055 /system/lib/libart.so (art::JniAbortF(char const*, char const*, ...)+68)
F/art ( 6837): art/runtime/runtime.cc:289] native: #10 pc 000b530f /system/lib/libart.so (art::ScopedCheck::ScopedCheck(_JNIEnv*, int, char const*)+1346)
F/art ( 6837): art/runtime/runtime.cc:289] native: #11 pc 000b66cd /system/lib/libart.so (art::CheckJNI::NewGlobalRef(_JNIEnv*, _jobject*)+28)
F/art ( 6837): art/runtime/runtime.cc:289] native: #12 pc 001ea0a7 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QJNIObjectPrivate::QJNIObjectPrivate(_jobject*)+82)
F/art ( 6837): art/runtime/runtime.cc:289] native: #13 pc 001ea69d /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (???)
F/art ( 6837): art/runtime/runtime.cc:289] native: #14 pc 001ec719 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QJNIObjectPrivate::getStaticObjectField(char const*, char const*, char const*)+48)
F/art ( 6837): art/runtime/runtime.cc:289] native: #15 pc 0017718d /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (???)
F/art ( 6837): art/runtime/runtime.cc:289] native: #16 pc 00177a3d /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QStandardPaths::writableLocation(QStandardPaths::StandardLocation)+860)
F/art ( 6837): art/runtime/runtime.cc:289] native: #17 pc 0017841f /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QStandardPaths::standardLocations(QStandardPaths::StandardLocation)+790)
F/art ( 6837): art/runtime/runtime.cc:289] native: #18 pc 00013e5b /data/app/org.qtproject.example.TouchImage-2/lib/arm/libTouchImage.so (ApplicationController::openFileButtonClicked()+130)
F/art ( 6837): art/runtime/runtime.cc:289] native: #19 pc 001cce4f /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QMetaObject::activate(QObject*, int, int, void**)+394)
F/art ( 6837): art/runtime/runtime.cc:289] native: #20 pc 00261987 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QAbstractButton::clicked(bool)+26)
F/art ( 6837): art/runtime/runtime.cc:289] native: #21 pc 001460f9 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (???)
F/art ( 6837): art/runtime/runtime.cc:289] native: #22 pc 001468f7 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (???)
F/art ( 6837): art/runtime/runtime.cc:289] native: #23 pc 00146979 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QAbstractButton::mouseReleaseEvent(QMouseEvent*)+88)
F/art ( 6837): art/runtime/runtime.cc:289] native: #24 pc 0019d509 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QToolButton::mouseReleaseEvent(QMouseEvent*)+4)
F/art ( 6837): art/runtime/runtime.cc:289] native: #25 pc 00100bbd /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QWidget::event(QEvent*)+536)
F/art ( 6837): art/runtime/runtime.cc:289] native: #26 pc 0019d57d /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QToolButton::event(QEvent*)+50)
F/art ( 6837): art/runtime/runtime.cc:289] native: #27 pc 000e2a41 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QApplicationPrivate::notify_helper(QObject*, QEvent*)+104)
F/art ( 6837): art/runtime/runtime.cc:289] native: #28 pc 000e5583 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QApplication::notify(QObject*, QEvent*)+1382)
F/art ( 6837): art/runtime/runtime.cc:289] native: #29 pc 001ae40f /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QCoreApplication::notifyInternal(QObject*, QEvent*)+62)
F/art ( 6837): art/runtime/runtime.cc:289] native: #30 pc 000e4d5b /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QApplicationPrivate::sendMouseEvent(QWidget*, QMouseEvent*, QWidget*, QWidget*, QWidget**, QPointer<QWidget>&, bool)+286)
F/art ( 6837): art/runtime/runtime.cc:289] native: #31 pc 0010a19b /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (???)
F/art ( 6837): art/runtime/runtime.cc:289] native: #32 pc 0010a8d3 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (???)
F/art ( 6837): art/runtime/runtime.cc:289] native: #33 pc 000e2a41 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QApplicationPrivate::notify_helper(QObject*, QEvent*)+104)
F/art ( 6837): art/runtime/runtime.cc:289] native: #34 pc 000e5e53 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Widgets.so (QApplication::notify(QObject*, QEvent*)+3638)
F/art ( 6837): art/runtime/runtime.cc:289] native: #35 pc 001ae40f /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QCoreApplication::notifyInternal(QObject*, QEvent*)+62)
F/art ( 6837): art/runtime/runtime.cc:289] native: #36 pc 000a09cd /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Gui.so (QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent*)+516)
F/art ( 6837): art/runtime/runtime.cc:289] native: #37 pc 000a06ed /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Gui.so (QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::TouchEvent*)+3492)
F/art ( 6837): art/runtime/runtime.cc:289] native: #38 pc 000a1b13 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Gui.so (QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent*)+382)
F/art ( 6837): art/runtime/runtime.cc:289] native: #39 pc 00093181 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Gui.so (QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>)+20)
F/art ( 6837): art/runtime/runtime.cc:289] native: #40 pc 00028135 /data/data/org.qtproject.example.TouchImage/qt-reserved-files/plugins/platforms/android/libqtforandroid.so (???)
F/art ( 6837): art/runtime/runtime.cc:289] native: #41 pc 001ad533 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)+14)
F/art ( 6837): art/runtime/runtime.cc:289] native: #42 pc 001adc13 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>)+226)
F/art ( 6837): art/runtime/runtime.cc:289] native: #43 pc 001b2527 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libQt5Core.so (QCoreApplication::exec()+82)
F/art ( 6837): art/runtime/runtime.cc:289] native: #44 pc 00012a41 /data/app/org.qtproject.example.TouchImage-2/lib/arm/libTouchImage.so (main+48)
F/art ( 6837): art/runtime/runtime.cc:289] native: #45 pc 000190b5 /data/data/org.qtproject.example.TouchImage/qt-reserved-files/plugins/platforms/android/libqtforandroid.so (???)
F/art ( 6837): art/runtime/runtime.cc:289] native: #46 pc 00016baf /system/lib/libc.so (__pthread_start(void*)+30)
F/art ( 6837): art/runtime/runtime.cc:289] native: #47 pc 00014af3 /system/lib/libc.so (__start_thread+6)
F/art ( 6837): art/runtime/runtime.cc:289] (no managed stack frames)
F/art ( 6837): art/runtime/runtime.cc:289] Pending exception android.content.ActivityNotFoundException thrown by 'unknown throw location'
F/art ( 6837): art/runtime/runtime.cc:289] android.content.ActivityNotFoundException: No Activity found to handle Intent
F/art ( 6837): art/runtime/runtime.cc:289] at void android.app.Instrumentation.checkStartActivityResult(int, java.lang.Object) (Instrumentation.java:1781)
F/art ( 6837): art/runtime/runtime.cc:289] at android.app.Instrumentation$ActivityResult android.app.Instrumentation.execStartActivity(android.content.Context, android.os.IBinder, android.os.IBinder, android.app.Activity, android.content.Intent, int, android.os.Bundle) (Instrumentation.java:1501)
F/art ( 6837): art/runtime/runtime.cc:289] at void android.app.Activity.startActivityForResult(android.content.Intent, int, android.os.Bundle) (Activity.java:3745)
F/art ( 6837): art/runtime/runtime.cc:289] at void android.app.Activity.startActivityForResult(android.content.Intent, int) (Activity.java:3706)
F/art ( 6837): art/runtime/runtime.cc:289] Dumping all threads without appropriate locks held: thread list lock mutator lock
F/art ( 6837): art/runtime/runtime.cc:289] All threads:
F/art ( 6837): art/runtime/runtime.cc:289] DALVIK THREADS (16):
F/art ( 6837): art/runtime/runtime.cc:289] (no managed stack frames)
<< lot more lines of log here >>
F/libc ( 6837): Fatal signal 6 (SIGABRT), code -6 in tid 6882 (QtThread)
这发生在 QtAndroid::startActivity 之后和 MyReceiver::handleActivityResult 之前(调试器这么说)。 更重要的是,程序启动过程中有警告/错误,但不会导致程序中止:
W/linker ( 4449): libQt5Gui.so: unused DT entry: type 0x1d arg 0x4c19d
W/linker ( 4449): libQt5Widgets.so: unused DT entry: type 0x1d arg 0x6a769
W/linker ( 4449): libQt5Svg.so: unused DT entry: type 0x1d arg 0x8f18
W/linker ( 4449): libQt5AndroidExtras.so: unused DT entry: type 0x1d arg 0x5044
W/linker ( 4449): libqtforandroid.so: unused DT entry: type 0x1d arg 0x8cac
I/Qt ( 4449): qt start
W/System.err( 4449): java.lang.NoSuchFieldException: mInsetState
W/System.err( 4449): at java.lang.Class.getDeclaredField(Class.java:890)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.getAccessibleField(ExtractStyle.java:405)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.getDrawable(ExtractStyle.java:1103)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.getLayerDrawable(ExtractStyle.java:629)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.getRippleDrawable(ExtractStyle.java:820)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.getDrawable(ExtractStyle.java:1028)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.extractViewInformations(ExtractStyle.java:1187)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.extractTextAppearanceInformations(ExtractStyle.java:1336)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.<init>(ExtractStyle.java:2017)
W/System.err( 4449): at org.qtproject.qt5.android.QtActivityDelegate.loadApplication(QtActivityDelegate.java:438)
W/System.err( 4449): at java.lang.reflect.Method.invoke(Native Method)
W/System.err( 4449): at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err( 4449): at org.qtproject.qt5.android.bindings.QtActivity.loadApplication(QtActivity.java:245)
W/System.err( 4449): at org.qtproject.qt5.android.bindings.QtActivity.startApp(QtActivity.java:655)
W/System.err( 4449): at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:895)
W/System.err( 4449): at android.app.Activity.performCreate(Activity.java:5990)
W/System.err( 4449): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
W/System.err( 4449): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
W/System.err( 4449): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
W/System.err( 4449): at android.app.ActivityThread.access$800(ActivityThread.java:151)
W/System.err( 4449): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
W/System.err( 4449): at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err( 4449): at android.os.Looper.loop(Looper.java:135)
W/System.err( 4449): at android.app.ActivityThread.main(ActivityThread.java:5254)
W/System.err( 4449): at java.lang.reflect.Method.invoke(Native Method)
W/System.err( 4449): at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err( 4449): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
W/System.err( 4449): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
W/System.err( 4449): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.reflect.Field.get(java.lang.Object)' on a null object reference
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.getDrawable(ExtractStyle.java:1103)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.getLayerDrawable(ExtractStyle.java:629)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.getRippleDrawable(ExtractStyle.java:820)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.getDrawable(ExtractStyle.java:1028)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.extractViewInformations(ExtractStyle.java:1187)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.extractTextAppearanceInformations(ExtractStyle.java:1336)
W/System.err( 4449): at org.qtproject.qt5.android.ExtractStyle.<init>(ExtractStyle.java:2017)
W/System.err( 4449): at org.qtproject.qt5.android.QtActivityDelegate.loadApplication(QtActivityDelegate.java:438)
W/System.err( 4449): at java.lang.reflect.Method.invoke(Native Method)
W/System.err( 4449): at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err( 4449): at org.qtproject.qt5.android.bindings.QtActivity.loadApplication(QtActivity.java:245)
W/System.err( 4449): at org.qtproject.qt5.android.bindings.QtActivity.startApp(QtActivity.java:655)
W/System.err( 4449): at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:895)
W/System.err( 4449): at android.app.Activity.performCreate(Activity.java:5990)
W/System.err( 4449): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
W/System.err( 4449): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
W/System.err( 4449): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
W/System.err( 4449): at android.app.ActivityThread.access$800(ActivityThread.java:151)
W/System.err( 4449): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
W/System.err( 4449): at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err( 4449): at android.os.Looper.loop(Looper.java:135)
W/System.err( 4449): at android.app.ActivityThread.main(ActivityThread.java:5254)
W/System.err( 4449): at java.lang.reflect.Method.invoke(Native Method)
W/System.err( 4449): at java.lang.reflect.Method.invoke(Method.java:372)
W/System.err( 4449): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
W/System.err( 4449): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
<< more lines of log here >>
W/linker ( 4449): libTouchImage.so: unused DT entry: type 0x1d arg 0x8efc
W/Qt A11Y ( 4449): Could not activate platform accessibility.
【问题讨论】:
【参考方案1】:这是一个愚蠢的错误。这是错误的方法签名(setAction 和 setType。正确的工作代码:
QAndroidJniObject ACTION_GET_CONTENT = QAndroidJniObject::fromString("android.intent.action.GET_CONTENT");
QAndroidJniObject intent("android/content/Intent");
if (ACTION_GET_CONTENT.isValid() && intent.isValid())
intent.callObjectMethod("setAction", "(Ljava/lang/String;)Landroid/content/Intent;", ACTION_GET_CONTENT.object<jstring>());
intent.callObjectMethod("setType", "(Ljava/lang/String;)Landroid/content/Intent;", QAndroidJniObject::fromString("file/*").object<jstring>());
QtAndroid::startActivity(intent.object<jobject>(), EXISTING_FILE_NAME_REQUEST, receiver);
return true;
else
return false;
【讨论】:
【参考方案2】:QAndroidJniObject ACTION_GET_CONTENT = QAndroidJniObject::fromString("android.intent.action.GET_CONTENT");
【讨论】:
添加一些解释可能会有用 我的方法不对吗?也许这是更简单的方法,但我不认为这是一个解决方案。但也许我错了,我现在无法测试。以上是关于Qt for Android - startActivityForResult 等效项不起作用的主要内容,如果未能解决你的问题,请参考以下文章
Necessitas SDK for android app with Qt
windows下Qt5.2 for android开发环境搭建
Android - 从 startActivity 获取活动对象
Qt 中的qserialplot 串口通信功能如何在qt for android用?或者用Qt如何实现android版本的串口通信功能?