Commit 802e3a0e authored by Johannes Schwab's avatar Johannes Schwab

client: catch exceptions thrown by startActivity

parent 4cc8e2f2
......@@ -19,8 +19,6 @@
#include "Backend.h"
#include "SqlBackend.h"
#include "Recipe.h"
//#include "RecipeTcpServer.h"
//#include "RecipeTcpClient.h"
#include "SynchronizeAsync.h"
#include "SendSyncKeyAsync.h"
#include "RecvSyncKeyAsync.h"
......@@ -29,6 +27,7 @@
#ifdef Q_OS_ANDROID
#include <QAndroidIntent>
#include <QtAndroid>
#include <QAndroidJniEnvironment>
#endif
#include <cassert>
......@@ -333,16 +332,31 @@ void Backend::requestImage() {
intent.handle().callObjectMethod("addCategory", "(Ljava/lang/String;)Landroid/content/Intent;", category.object<jstring>());
QtAndroid::startActivity(intent.handle(), static_cast<int>(AndroidRequestCodes::GetImage), &androidResultReceiver);
QAndroidJniEnvironment jniEnv;
if (jniEnv->ExceptionCheck()) jniEnv->ExceptionClear();
}
void Backend::requestQRCode() {
QAndroidIntent intent("com.google.zxing.client.android.SCAN");
QAndroidJniObject scanMode = QAndroidJniObject::fromString("SCAN_MODE");
QAndroidJniObject qrCodeMode = QAndroidJniObject::fromString("QR_CODE_MODE");
intent.handle().callObjectMethod("putExtra", "(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;", scanMode.object<jstring>(), qrCodeMode.object<jstring>());
QtAndroid::startActivity(intent.handle(), static_cast<int>(AndroidRequestCodes::GetQRCode), &androidResultReceiver);
QAndroidJniEnvironment jniEnv;
if (jniEnv->ExceptionCheck()) {
/* The user has no fitting app, so we let him install one */
jniEnv->ExceptionClear();
QAndroidJniObject uriString = QAndroidJniObject::fromString("market://details?id=com.google.zxing.client.android");
QAndroidJniObject uri = QAndroidJniObject::callStaticObjectMethod("android/net/Uri", "parse", "(Ljava/lang/String;)Landroid/net/Uri;", uriString.object<jstring>());
QAndroidIntent intent("android.intent.action.VIEW");
intent.handle().callObjectMethod("setData", "(Landroid/net/Uri;)Landroid/content/Intent;", uri.object());
QtAndroid::startActivity(intent.handle(), 0);
/* If we get an error here, there is no app store on the phone */
if (jniEnv->ExceptionCheck()) jniEnv->ExceptionClear();
}
}
void Backend::shareRecipe(Recipe *recipe) {
......@@ -352,7 +366,7 @@ void Backend::shareRecipe(Recipe *recipe) {
QAndroidJniObject metaType = QAndroidJniObject::fromString("openrecipes/recipe_xml");
intent.handle().callObjectMethod("setType", "(Ljava/lang/String;)Landroid/content/Intent;", metaType.object<jstring>());
QAndroidJniObject contentUriString = QAndroidJniObject::fromString(QString("content://org.jschwab.openrecipes.provider/recipe_xml/%1").arg(idHex));
QAndroidJniObject contentUri = QAndroidJniObject::callStaticObjectMethod("android/net/Uri", "parse", "(Ljava/lang/String;)Landroid/net/Uri;", contentUriString.object<jstring>());
QAndroidJniObject extraStream = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "EXTRA_STREAM");
......@@ -362,6 +376,8 @@ void Backend::shareRecipe(Recipe *recipe) {
QAndroidJniObject chooser = QAndroidJniObject::callStaticObjectMethod("android/content/Intent", "createChooser", "(Landroid/content/Intent;Ljava/lang/CharSequence;)Landroid/content/Intent;", intent.handle().object(), title.object<jstring>());
QtAndroid::startActivity(chooser, 0);
QAndroidJniEnvironment jniEnv;
if (jniEnv->ExceptionCheck()) jniEnv->ExceptionClear();
}
#else
bool Backend::importRecipeFromFile(const QString &path) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment