Skip to content

Commit

Permalink
Added method to request to send email
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsinSoft committed Jan 7, 2024
1 parent e1a1649 commit cf3b0d8
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
11 changes: 3 additions & 8 deletions Documentation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -654,16 +654,11 @@ <h3>Audio</h3>
</div>
<div class="section-txt" id="System">
<h3>System</h3>
<p>This tool export the system paths as follow:</p>
<p>This tool allow to request to send an email:</p>
<pre class="prettyprint">import QtAndroidTools 1.0

QtAndroidSystem.dataLocation
QtAndroidSystem.configLocation
QtAndroidSystem.downloadLocation
QtAndroidSystem.musicLocation
QtAndroidSystem.moviesLocation
QtAndroidSystem.picturesLocation</pre>
<p>For documentation about each path value refer to the official documentation <a href="https://doc.qt.io/qt-5/qstandardpaths.html" target="_blank">here</a>.</p>
QtAndroidSystem.requestEmailSend(emails, subject, body, description)</pre>
<p><i>emails</i> is an array of email addresses to send same email to multiple destinations. <i>subject</i> and <i>body</i> can prefill the mail content and <i>description</i> is a text advising the user regarding the requested action.</p>
<p>It also export three simply conversion functions from graphic units to pixel size:</p>
<pre class="prettyprint">import QtAndroidTools 1.0

Expand Down
26 changes: 26 additions & 0 deletions QtAndroidTools/QAndroidSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,29 @@ int QAndroidSystem::ptToPx(float pt)
}
return -1;
}

bool QAndroidSystem::requestEmailSend(const QStringList &emailsList, const QString &subject, const QString &body, const QString &description)
{
if(m_javaSystem.isValid())
{
const QJniObject stringObj("java/lang/String");
QJniObject stringArrayObj;
QJniEnvironment jniEnv;

stringArrayObj = QJniObject::fromLocalRef(jniEnv->NewObjectArray(emailsList.count(), jniEnv->GetObjectClass(stringObj.object()), NULL));

for(int i = 0; i < emailsList.count(); i++)
{
jniEnv->SetObjectArrayElement(stringArrayObj.object<jobjectArray>(), i, QJniObject::fromString(emailsList[i]).object<jstring>());
}

return m_javaSystem.callMethod<jboolean>("requestEmailSend",
"([Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z",
stringArrayObj.object<jobjectArray>(),
QJniObject::fromString(subject).object<jstring>(),
QJniObject::fromString(body).object<jstring>(),
QJniObject::fromString(description).object<jstring>()
);
}
return false;
}
2 changes: 2 additions & 0 deletions QtAndroidTools/QAndroidSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class QAndroidSystem : public QObject
Q_INVOKABLE int dipToPx(float dip);
Q_INVOKABLE int ptToPx(float pt);

Q_INVOKABLE bool requestEmailSend(const QStringList &emailsList, const QString &subject, const QString &body, const QString &description);

private:
const QJniObject m_javaSystem;
static QAndroidSystem *m_pInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,25 @@ public int ptToPx(float pt)
{
return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PT, pt, mActivityInstance.getResources().getDisplayMetrics());
}

public boolean requestEmailSend(String[] emails, String subject, String body, String description)
{
final Intent intent = new Intent(Intent.ACTION_SENDTO);

intent.setType("message/rfc822");
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, emails);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, body);
try
{
mActivityInstance.startActivity(Intent.createChooser(intent, description));
}
catch(android.content.ActivityNotFoundException ex)
{
return false;
}

return true;
}
}
13 changes: 12 additions & 1 deletion QtAndroidToolsDemo/tools/AndroidSystem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ ScrollablePage {
padding: 20

Column {
anchors.fill: parent
width: parent.width * 0.9
anchors.centerIn: parent
spacing: 5

Label {
anchors.horizontalCenter: parent.horizontalCenter
text: "Request to send email"
font.bold: true
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: "Request send"
onClicked: QtAndroidSystem.requestEmailSend(["[email protected]"], "This is the subject", "This is the body", "Request to send email")
}
}
}

0 comments on commit cf3b0d8

Please sign in to comment.