我正在使用Qt开发一个Android应用程序.现在,我要让用户共享我应用程序中的图像.我试图创建新的Intent:
package ir.qtips;import androID.content.Intent;import androID.net.Uri;public class ShareActivity extends org.qtproject.qt5.androID.bindings.QtActivity{ private static ShareActivity instance; ShareActivity() { instance = this; } public voID createInstagramIntent(){ String type = "image/*"; String captionText = "<< media caption >>"; // Create the new Intent using the 'Send' action. Intent share = new Intent(Intent.ACTION_SEND); // Set the MIME type share.setType(type); // Add the URI and the caption to the Intent. share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/a.jpg")); share.putExtra(Intent.EXTRA_TEXT, caption); // broadcast the Intent. startActivity(Intent.createChooser(share, "Share to")); }}
然后我尝试从C调用createInstagramIntent:
#ifdef Q_OS_ANDROID QAndroIDJniObject jni("ir/qtips/ShareActivity"); jni.callMethod<voID>("createInstagramIntent");#endif
但这行不通.
在应用程序的日志中,我认为一行比其他行更重要:@H_419_18@
java.lang.RuntimeException: Can't create handler insIDe thread that has not called Looper.prepare()
解决方法:
您不能从尚未名为Looper.prepare()的线程创建Handler Thread.您可以做的是创建一个处理程序线程,如下所示:使用Looper静态类
Handler handler = new Handler(Looper.getMainLooper());
这是一个称为AndroID Text to Speech Service的example project.您可以按照以下代码来解决您的问题,因为“文字转语音”也应被称为“共享意图”
显示/隐藏键盘示例,还需要从UI线程中调用它.它可以帮助您.
{ public voID setSuspendSleep() { this.runOnUiThread( new Runnable() { public voID run() { getwindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON ); } } ); } public voID setAllowSleep() { this.runOnUiThread( new Runnable() { public voID run() { getwindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } } ); }}------- and then in C++ ------// getwindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);// getwindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);extern "C" voID SuspendSleep( int bStopSleep ){ static int init; static jobject WindowManager_LayoutParams_FLAG_KEEP_SCREEN_ON; // Attaches the current thread to the JVM. jint lResult; jint lFlags = 0; JavaVM* lJavaVM = engine.app->activity->vm; jnienv* ljnienv = engine.app->activity->env; JavaVMAttachArgs lJavaVMAttachArgs; lJavaVMAttachArgs.version = JNI_VERSION_1_6; lJavaVMAttachArgs.name = "NativeThread"; lJavaVMAttachArgs.group = NulL; lResult=lJavaVM->AttachCurrentThread(&ljnienv, &lJavaVMAttachArgs); if (lResult == JNI_ERR) { return; } // RetrIEves NativeActivity. jobject lNativeActivity = engine.app->activity->clazz; jclass ClassNativeActivity = ljnienv->GetobjectClass(lNativeActivity); if( bStopSleep ) { jmethodID MethodSetFlags = ljnienv->getmethodID( ClassNativeActivity, "setSuspendSleep", "()V"); if( MethodSetFlags ) ljnienv->CallVoIDMethod( lNativeActivity, MethodSetFlags ); } else { jmethodID MethodSetFlags = ljnienv->getmethodID( ClassNativeActivity, "setAllowSleep", "()V"); if( MethodSetFlags ) ljnienv->CallVoIDMethod( lNativeActivity, MethodSetFlags ); } // Finished with the JVM. lJavaVM->DetachCurrentThread();}
总结 以上是内存溢出为你收集整理的如何让用户共享使用Qt for Android编写的我的应用中的图像全部内容,希望文章能够帮你解决如何让用户共享使用Qt for Android编写的我的应用中的图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)