-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.cpp
41 lines (38 loc) · 1.75 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "utils.h"
#ifndef WINVER
#include <QAndroidJniObject>
#include <QtAndroid>
#include <QAndroidJniEnvironment>
QAndroidJniObject View;
QAndroidJniObject MIME;
QAndroidJniObject Subject;
QAndroidJniObject Text;
QAndroidJniObject Name;
QAndroidJniObject Str;
QAndroidJniObject intent("android/content/Intent");
QAndroidJniObject intent2;
#endif
void share(QString str)
{
#ifndef WINVER
View = QAndroidJniObject::fromString("android.intent.action.VIEW");
MIME = QAndroidJniObject::fromString("text/plain");
Subject = QAndroidJniObject::fromString("android.intent.extra.SUBJECT");
Text = QAndroidJniObject::fromString("android.intent.extra.TEXT");
Name = QAndroidJniObject::fromString("分享");
Str = QAndroidJniObject::fromString(str);
intent.callObjectMethod("addAction","(Ljava/lang/String;)Landroid/content/Intent;",View.object<jstring>());
intent.callObjectMethod("setType","(Ljava/lang/String;)Landroid/content/Intent;",MIME.object<jstring>());
intent.callObjectMethod("putExtra","(Ljava/lang/String;Ljava/lang/string;)Landroid/content/Intent;",Subject.object<jstring>(),
Name.object<jstring>());
intent.callObjectMethod("putExtra","(Ljava/lang/String;Ljava/lang/string;)Landroid/content/Intent;",
Text.object<jstring>(),Str.object<jstring>());
intent.callObjectMethod("setFlags","(I)Landroid/content/Intent;",268435456);
intent2 = QAndroidJniObject::callStaticObjectMethod("android/content/Intent","createChooser",
"(Landroid/content/Intent;Ljava/lang/CharSequence;)Landroid/content/Intent;",
intent.object<jobject>(),Name.object<jstring>());
QtAndroid::startActivity(intent2,123456);
#else
return;
#endif
}