mirror of
https://github.com/QuasarApp/QtAndroidTools.git
synced 2025-04-27 05:24:31 +00:00
Demo app now receive shared text and binary image data
This commit is contained in:
parent
fb68c3a3da
commit
30d266af75
@ -51,19 +51,23 @@ public class AndroidSharing
|
||||
|
||||
public int getAction()
|
||||
{
|
||||
final String ActionValue = mActivityIntent.getAction();
|
||||
int ActionId = ACTION_NONE;
|
||||
|
||||
switch(mActivityIntent.getAction())
|
||||
if(ActionValue != null)
|
||||
{
|
||||
case Intent.ACTION_SEND:
|
||||
ActionId = ACTION_SEND;
|
||||
break;
|
||||
case Intent.ACTION_SEND_MULTIPLE:
|
||||
ActionId = ACTION_SEND_MULTIPLE;
|
||||
break;
|
||||
case Intent.ACTION_PICK:
|
||||
ActionId = ACTION_PICK;
|
||||
break;
|
||||
switch(ActionValue)
|
||||
{
|
||||
case Intent.ACTION_SEND:
|
||||
ActionId = ACTION_SEND;
|
||||
break;
|
||||
case Intent.ACTION_SEND_MULTIPLE:
|
||||
ActionId = ACTION_SEND_MULTIPLE;
|
||||
break;
|
||||
case Intent.ACTION_PICK:
|
||||
ActionId = ACTION_PICK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionId;
|
||||
|
@ -14,6 +14,7 @@ int main(int argc, char *argv[])
|
||||
#ifdef Q_OS_ANDROID
|
||||
QtAndroidTools::InitializeQmlTools();
|
||||
#endif
|
||||
QObject::connect(&engine, SIGNAL(quit()), &app, SLOT(quit()));
|
||||
engine.load(QUrl(QStringLiteral("qrc:/Main.qml")));
|
||||
if(engine.rootObjects().isEmpty()) return -1;
|
||||
|
||||
|
@ -3,6 +3,7 @@ import QtQuick 2.11
|
||||
import QtQuick.Layouts 1.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Controls.Material 2.12
|
||||
import QtAndroidTools 1.0
|
||||
|
||||
ApplicationWindow {
|
||||
id: window
|
||||
@ -11,6 +12,13 @@ ApplicationWindow {
|
||||
height: 520
|
||||
title: "QtAndroidTools Demo"
|
||||
|
||||
Component.onCompleted: {
|
||||
if(QtAndroidSharing.action !== QtAndroidSharing.ACTION_NONE)
|
||||
{
|
||||
stackView.push("qrc:/tools/AndroidSharing.qml");
|
||||
}
|
||||
}
|
||||
|
||||
header: ToolBar {
|
||||
Material.foreground: "white"
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Dialogs 1.1
|
||||
import QtAndroidTools 1.0
|
||||
|
||||
Page {
|
||||
@ -7,9 +8,19 @@ Page {
|
||||
padding: 20
|
||||
|
||||
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"
|
||||
font.bold: true
|
||||
}
|
||||
TextInput {
|
||||
TextField {
|
||||
id: sharedText
|
||||
width: parent.width
|
||||
text: "Hello Qt!"
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
horizontalAlignment: TextField.AlignHCenter
|
||||
}
|
||||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: "Share"
|
||||
onClicked: QtAndroidSharing.shareText(sharedText.text)
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: "Received shared text"
|
||||
font.bold: true
|
||||
}
|
||||
Label {
|
||||
id: receivedSharedtext
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
MessageDialog {
|
||||
id: receivedSharedText
|
||||
title: "Received shared text"
|
||||
onAccepted: Qt.quit()
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user