mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-29 16:47:25 -04:00
Implement Android intent handling in qml app
AndroidManifest.xml register activity as an handler for retroshare links RetroShareQmlActivity...NativeCalls.cpp bring the intent data from java to C++ and then to QML QMl mainWindow uses URI.js to parse the received uri Create a singleton for qml engine so it is reachable from NativeCalls
This commit is contained in:
parent
29a3d105c4
commit
533dbef0c7
15 changed files with 239 additions and 26 deletions
|
@ -10,16 +10,24 @@
|
|||
android:label="RetroShare QML"
|
||||
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation"
|
||||
android:screenOrientation="unspecified"
|
||||
android:launchMode="singleTop">
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
|
||||
<!-- Application to launch -->
|
||||
<meta-data android:name="android.app.lib_name" android:value="retroshare-qml-app"/>
|
||||
<!-- Application to launch -->
|
||||
<!-- Register for retroshare:// and rtsh:// link handling -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.BROWSABLE"/>
|
||||
<data android:scheme="retroshare" />
|
||||
<data android:scheme="rtsh" />
|
||||
</intent-filter>
|
||||
|
||||
<!-- Qt Application to launch -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="retroshare-qml-app"/>
|
||||
<!-- Application arguments -->
|
||||
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
|
||||
<!-- Application arguments -->
|
||||
|
|
46
retroshare-qml-app/src/android/src/NativeCalls.cpp
Normal file
46
retroshare-qml-app/src/android/src/NativeCalls.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* RetroShare Android QML App
|
||||
* Copyright (C) 2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "NativeCalls.h"
|
||||
#include "singletonqmlengine.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QMetaObject>
|
||||
#include <QDebug>
|
||||
#include <QQuickWindow>
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_retroshare_android_qml_1app_jni_NativeCalls_notifyIntentUri
|
||||
(JNIEnv* env, jclass, jstring uri)
|
||||
{
|
||||
const char *uriBytes = env->GetStringUTFChars(uri, NULL);
|
||||
QString uriStr(uriBytes);
|
||||
env->ReleaseStringUTFChars(uri, uriBytes);
|
||||
|
||||
QQmlApplicationEngine& engine(SingletonQmlEngine::instance());
|
||||
QObject* rootObj = engine.rootObjects()[0];
|
||||
QQuickWindow* mainWindow = qobject_cast<QQuickWindow*>(rootObj);
|
||||
|
||||
if(mainWindow)
|
||||
{
|
||||
QMetaObject::invokeMethod(mainWindow, "handleIntentUri",
|
||||
Q_ARG(QVariant, uriStr));
|
||||
}
|
||||
else qCritical() << __PRETTY_FUNCTION__ << "Root object is not a window!";
|
||||
}
|
|
@ -26,6 +26,8 @@ import android.util.Log;
|
|||
|
||||
import org.qtproject.qt5.android.bindings.QtActivity;
|
||||
|
||||
import org.retroshare.android.qml_app.jni.NativeCalls;
|
||||
|
||||
public class RetroShareQmlActivity extends QtActivity
|
||||
{
|
||||
@Override
|
||||
|
@ -50,6 +52,18 @@ public class RetroShareQmlActivity extends QtActivity
|
|||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewIntent(Intent intent)
|
||||
{
|
||||
super.onNewIntent(intent);
|
||||
String uri = intent.getDataString();
|
||||
if (uri != null)
|
||||
{
|
||||
Log.d("RetroShareQmlActivity", "onNewIntent() " + uri);
|
||||
NativeCalls.notifyIntentUri(uri);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMyServiceRunning(Class<?> serviceClass)
|
||||
{
|
||||
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* RetroShare Android Service
|
||||
* Copyright (C) 2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.retroshare.android.qml_app.jni;
|
||||
|
||||
public class NativeCalls
|
||||
{
|
||||
public static native void notifyIntentUri(String uri);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class org_retroshare_android_qml_app_jni_NativeCalls */
|
||||
|
||||
#ifndef _Included_org_retroshare_android_qml_app_jni_NativeCalls
|
||||
#define _Included_org_retroshare_android_qml_app_jni_NativeCalls
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: org_retroshare_android_qml_app_jni_NativeCalls
|
||||
* Method: notifyIntentUri
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_retroshare_android_qml_1app_jni_NativeCalls_notifyIntentUri
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue