mirror of
https://github.com/QuasarApp/QtAndroidTools.git
synced 2025-04-30 06:54:31 +00:00
Added tool for share text with other apps
This commit is contained in:
parent
934b6c7c5d
commit
ea98dc0504
QtAndroidTools
QAndroidSharing.cppQAndroidSharing.hQtAndroidTools.cppQtAndroidTools.pri
src/com/falsinsoft/qtandroidtools
QtAndroidToolsDemo
57
QtAndroidTools/QAndroidSharing.cpp
Normal file
57
QtAndroidTools/QAndroidSharing.cpp
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018 Fabio Falsini <falsinsoft@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
#include "QAndroidSharing.h"
|
||||||
|
|
||||||
|
QAndroidSharing *QAndroidSharing::m_pInstance = nullptr;
|
||||||
|
|
||||||
|
QAndroidSharing::QAndroidSharing() : m_JavaSharing("com/falsinsoft/qtandroidtools/AndroidSharing",
|
||||||
|
"(Landroid/app/Activity;)V",
|
||||||
|
QtAndroid::androidActivity().object<jobject>())
|
||||||
|
{
|
||||||
|
m_pInstance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject* QAndroidSharing::qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine)
|
||||||
|
{
|
||||||
|
Q_UNUSED(engine);
|
||||||
|
Q_UNUSED(scriptEngine);
|
||||||
|
|
||||||
|
return new QAndroidSharing();
|
||||||
|
}
|
||||||
|
|
||||||
|
QAndroidSharing* QAndroidSharing::instance()
|
||||||
|
{
|
||||||
|
return m_pInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QAndroidSharing::shareText(const QString &Text)
|
||||||
|
{
|
||||||
|
if(m_JavaSharing.isValid())
|
||||||
|
{
|
||||||
|
m_JavaSharing.callMethod<void>("shareText",
|
||||||
|
"(Ljava/lang/String;)V",
|
||||||
|
QAndroidJniObject::fromString(Text).object<jstring>()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
46
QtAndroidTools/QAndroidSharing.h
Normal file
46
QtAndroidTools/QAndroidSharing.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018 Fabio Falsini <falsinsoft@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QtAndroidExtras>
|
||||||
|
#include <QQmlEngine>
|
||||||
|
|
||||||
|
class QAndroidSharing : public QObject
|
||||||
|
{
|
||||||
|
Q_DISABLE_COPY(QAndroidSharing)
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QAndroidSharing();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static QObject* qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine);
|
||||||
|
static QAndroidSharing* instance();
|
||||||
|
|
||||||
|
Q_INVOKABLE void shareText(const QString &Text);
|
||||||
|
|
||||||
|
private:
|
||||||
|
const QAndroidJniObject m_JavaSharing;
|
||||||
|
static QAndroidSharing *m_pInstance;
|
||||||
|
};
|
@ -67,6 +67,9 @@
|
|||||||
#ifdef QTAT_GOOGLE_DRIVE
|
#ifdef QTAT_GOOGLE_DRIVE
|
||||||
#include "QAndroidGoogleDrive.h"
|
#include "QAndroidGoogleDrive.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef QTAT_SHARING
|
||||||
|
#include "QAndroidSharing.h"
|
||||||
|
#endif
|
||||||
#include "QtAndroidTools.h"
|
#include "QtAndroidTools.h"
|
||||||
|
|
||||||
QtAndroidTools::QtAndroidTools()
|
QtAndroidTools::QtAndroidTools()
|
||||||
@ -120,4 +123,7 @@ void QtAndroidTools::InitializeQmlTools()
|
|||||||
#ifdef QTAT_GOOGLE_DRIVE
|
#ifdef QTAT_GOOGLE_DRIVE
|
||||||
qmlRegisterSingletonType<QAndroidGoogleDrive>("QtAndroidTools", 1, 0, "QtAndroidGoogleDrive", &QAndroidGoogleDrive::qmlInstance);
|
qmlRegisterSingletonType<QAndroidGoogleDrive>("QtAndroidTools", 1, 0, "QtAndroidGoogleDrive", &QAndroidGoogleDrive::qmlInstance);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef QTAT_SHARING
|
||||||
|
qmlRegisterSingletonType<QAndroidSharing>("QtAndroidTools", 1, 0, "QtAndroidSharing", &QAndroidSharing::qmlInstance);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -142,3 +142,12 @@ contains(DEFINES, QTAT_GOOGLE_DRIVE) {
|
|||||||
PRE_TARGETDEPS += copy_google_drive
|
PRE_TARGETDEPS += copy_google_drive
|
||||||
QMAKE_EXTRA_TARGETS += copy_google_drive
|
QMAKE_EXTRA_TARGETS += copy_google_drive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contains(DEFINES, QTAT_SHARING) {
|
||||||
|
HEADERS += $$PWD/QAndroidSharing.h
|
||||||
|
SOURCES += $$PWD/QAndroidSharing.cpp
|
||||||
|
OTHER_FILES += $$PWD/src/com/falsinsoft/qtandroidtools/AndroidSharing.java
|
||||||
|
copy_sharing.commands = $(COPY_FILE) $$shell_path($$PWD/src/com/falsinsoft/qtandroidtools/AndroidSharing.java) $$shell_path($$ANDROID_PACKAGE_SOURCE_DIR/src/com/falsinsoft/qtandroidtools/)
|
||||||
|
PRE_TARGETDEPS += copy_sharing
|
||||||
|
QMAKE_EXTRA_TARGETS += copy_sharing
|
||||||
|
}
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2018 Fabio Falsini <falsinsoft@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.falsinsoft.qtandroidtools;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.content.pm.ResolveInfo;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
|
||||||
|
public class AndroidSharing
|
||||||
|
{
|
||||||
|
private final Activity mActivityInstance;
|
||||||
|
|
||||||
|
public AndroidSharing(Activity ActivityInstance)
|
||||||
|
{
|
||||||
|
mActivityInstance = ActivityInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shareText(String Text)
|
||||||
|
{
|
||||||
|
Intent SendIntent = new Intent();
|
||||||
|
SendIntent.setAction(Intent.ACTION_SEND);
|
||||||
|
SendIntent.putExtra(Intent.EXTRA_TEXT, Text);
|
||||||
|
SendIntent.setType("text/plain");
|
||||||
|
|
||||||
|
Intent ShareIntent = Intent.createChooser(SendIntent, null);
|
||||||
|
mActivityInstance.startActivity(ShareIntent);
|
||||||
|
}
|
||||||
|
}
|
@ -97,6 +97,7 @@ ApplicationWindow {
|
|||||||
ListElement { title: "PlayStore"; source: "qrc:/tools/AndroidPlayStore.qml" }
|
ListElement { title: "PlayStore"; source: "qrc:/tools/AndroidPlayStore.qml" }
|
||||||
ListElement { title: "GoogleAccount"; source: "qrc:/tools/AndroidGoogleAccount.qml" }
|
ListElement { title: "GoogleAccount"; source: "qrc:/tools/AndroidGoogleAccount.qml" }
|
||||||
ListElement { title: "GoogleDrive"; source: "qrc:/tools/AndroidGoogleDrive.qml" }
|
ListElement { title: "GoogleDrive"; source: "qrc:/tools/AndroidGoogleDrive.qml" }
|
||||||
|
ListElement { title: "Sharing"; source: "qrc:/tools/AndroidSharing.qml" }
|
||||||
ListElement { title: "System"; source: "qrc:/tools/AndroidSystem.qml" }
|
ListElement { title: "System"; source: "qrc:/tools/AndroidSystem.qml" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,8 @@ DEFINES += \
|
|||||||
QTAT_ADMOB_REWARDED_VIDEO \
|
QTAT_ADMOB_REWARDED_VIDEO \
|
||||||
QTAT_PLAY_STORE \
|
QTAT_PLAY_STORE \
|
||||||
QTAT_GOOGLE_ACCOUNT \
|
QTAT_GOOGLE_ACCOUNT \
|
||||||
QTAT_GOOGLE_DRIVE
|
QTAT_GOOGLE_DRIVE \
|
||||||
|
QTAT_SHARING
|
||||||
include(../QtAndroidTools/QtAndroidTools.pri)
|
include(../QtAndroidTools/QtAndroidTools.pri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,5 +17,6 @@
|
|||||||
<file>tools/AndroidGoogleAccount.qml</file>
|
<file>tools/AndroidGoogleAccount.qml</file>
|
||||||
<file>tools/AndroidGoogleDrive.qml</file>
|
<file>tools/AndroidGoogleDrive.qml</file>
|
||||||
<file>tools/AndroidSystem.qml</file>
|
<file>tools/AndroidSystem.qml</file>
|
||||||
|
<file>tools/AndroidSharing.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
@ -69,4 +69,15 @@ android {
|
|||||||
aaptOptions {
|
aaptOptions {
|
||||||
noCompress 'rcc'
|
noCompress 'rcc'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
packagingOptions {
|
||||||
|
exclude 'META-INF/DEPENDENCIES'
|
||||||
|
exclude 'META-INF/LICENSE'
|
||||||
|
exclude 'META-INF/LICENSE.txt'
|
||||||
|
exclude 'META-INF/license.txt'
|
||||||
|
exclude 'META-INF/NOTICE'
|
||||||
|
exclude 'META-INF/NOTICE.txt'
|
||||||
|
exclude 'META-INF/notice.txt'
|
||||||
|
exclude 'META-INF/ASL2.0'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
31
QtAndroidToolsDemo/tools/AndroidSharing.qml
Normal file
31
QtAndroidToolsDemo/tools/AndroidSharing.qml
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import QtQuick 2.12
|
||||||
|
import QtQuick.Controls 2.12
|
||||||
|
import QtQuick.Dialogs 1.3
|
||||||
|
import QtAndroidTools 1.0
|
||||||
|
|
||||||
|
ScrollablePage {
|
||||||
|
id: page
|
||||||
|
padding: 20
|
||||||
|
|
||||||
|
Column {
|
||||||
|
anchors.fill: parent
|
||||||
|
spacing: 20
|
||||||
|
|
||||||
|
Label {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
text: "Text to share"
|
||||||
|
font.bold: true
|
||||||
|
}
|
||||||
|
TextInput {
|
||||||
|
id: sharedText
|
||||||
|
width: parent.width
|
||||||
|
text: "Hello Qt!"
|
||||||
|
horizontalAlignment: TextInput.AlignHCenter
|
||||||
|
}
|
||||||
|
Button {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
text: "Share"
|
||||||
|
onClicked: QtAndroidSharing.shareText(sharedText.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user