Demo app now receive shared text and binary image data

This commit is contained in:
FalsinSoft 2020-02-14 16:04:15 +01:00
parent fb68c3a3da
commit 30d266af75
4 changed files with 60 additions and 22 deletions

View File

@ -51,9 +51,12 @@ public class AndroidSharing
public int getAction() public int getAction()
{ {
final String ActionValue = mActivityIntent.getAction();
int ActionId = ACTION_NONE; int ActionId = ACTION_NONE;
switch(mActivityIntent.getAction()) if(ActionValue != null)
{
switch(ActionValue)
{ {
case Intent.ACTION_SEND: case Intent.ACTION_SEND:
ActionId = ACTION_SEND; ActionId = ACTION_SEND;
@ -65,6 +68,7 @@ public class AndroidSharing
ActionId = ACTION_PICK; ActionId = ACTION_PICK;
break; break;
} }
}
return ActionId; return ActionId;
} }

View File

@ -14,6 +14,7 @@ int main(int argc, char *argv[])
#ifdef Q_OS_ANDROID #ifdef Q_OS_ANDROID
QtAndroidTools::InitializeQmlTools(); QtAndroidTools::InitializeQmlTools();
#endif #endif
QObject::connect(&engine, SIGNAL(quit()), &app, SLOT(quit()));
engine.load(QUrl(QStringLiteral("qrc:/Main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/Main.qml")));
if(engine.rootObjects().isEmpty()) return -1; if(engine.rootObjects().isEmpty()) return -1;

View File

@ -3,6 +3,7 @@ import QtQuick 2.11
import QtQuick.Layouts 1.12 import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12 import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.12 import QtQuick.Controls.Material 2.12
import QtAndroidTools 1.0
ApplicationWindow { ApplicationWindow {
id: window id: window
@ -11,6 +12,13 @@ ApplicationWindow {
height: 520 height: 520
title: "QtAndroidTools Demo" title: "QtAndroidTools Demo"
Component.onCompleted: {
if(QtAndroidSharing.action !== QtAndroidSharing.ACTION_NONE)
{
stackView.push("qrc:/tools/AndroidSharing.qml");
}
}
header: ToolBar { header: ToolBar {
Material.foreground: "white" Material.foreground: "white"

View File

@ -1,5 +1,6 @@
import QtQuick 2.12 import QtQuick 2.12
import QtQuick.Controls 2.12 import QtQuick.Controls 2.12
import QtQuick.Dialogs 1.1
import QtAndroidTools 1.0 import QtAndroidTools 1.0
Page { Page {
@ -7,9 +8,19 @@ Page {
padding: 20 padding: 20
Component.onCompleted: { Component.onCompleted: {
if(QtAndroidSharing.action !== QtAndroidSharing.ACTION_NONE) if(QtAndroidSharing.action === QtAndroidSharing.ACTION_SEND)
{ {
if(QtAndroidSharing.mimeType === "text/plain") receivedSharedtext.text = QtAndroidSharing.getSharedText(); if(QtAndroidSharing.mimeType === "text/plain")
{
receivedSharedText.text = QtAndroidSharing.getSharedText();
receivedSharedText.open();
}
else if(QtAndroidSharing.mimeType.startsWith("image") === true)
{
QtAndroidTools.insertImage("SharedImage", QtAndroidSharing.getSharedData());
sharedImage.source = "image://QtAndroidTools/SharedImage";
receivedSharedImage.open();
}
} }
} }
@ -22,26 +33,40 @@ Page {
text: "Text to share" text: "Text to share"
font.bold: true font.bold: true
} }
TextInput { TextField {
id: sharedText id: sharedText
width: parent.width width: parent.width
text: "Hello Qt!" text: "Hello Qt!"
horizontalAlignment: TextInput.AlignHCenter horizontalAlignment: TextField.AlignHCenter
} }
Button { Button {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
text: "Share" text: "Share"
onClicked: QtAndroidSharing.shareText(sharedText.text) onClicked: QtAndroidSharing.shareText(sharedText.text)
} }
}
Label { MessageDialog {
anchors.horizontalCenter: parent.horizontalCenter id: receivedSharedText
text: "Received shared text" title: "Received shared text"
font.bold: true onAccepted: Qt.quit()
}
Label {
id: receivedSharedtext
anchors.horizontalCenter: parent.horizontalCenter
} }
Dialog {
id: receivedSharedImage
title: "Received shared image"
modal: true
standardButtons: Dialog.Ok
contentWidth: sharedImage.width
contentHeight: sharedImage.height
anchors.centerIn: parent
Image {
id: sharedImage
width: page.width * 0.5
height: width
}
onAccepted: Qt.quit()
} }
} }