File indexing completed on 2024-11-17 04:43:12
0001 /* 0002 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KANDROIDEXTRAS_INTENT_H 0008 #define KANDROIDEXTRAS_INTENT_H 0009 0010 #include "kandroidextras_export.h" 0011 0012 #include <KAndroidExtras/AndroidTypes> 0013 #include <KAndroidExtras/JniMethod> 0014 #include <KAndroidExtras/JniProperty> 0015 #include <KAndroidExtras/JavaTypes> 0016 #include <KAndroidExtras/Uri> 0017 0018 class QUrl; 0019 0020 namespace KAndroidExtras { 0021 0022 /** Methods to interact with android.content.Intent objects. 0023 * This does not only offer features beyond what QAndroidIntent, it also provides 0024 * a putExtra() implementation that actually interoperates with system services. 0025 */ 0026 class KANDROIDEXTRAS_EXPORT Intent 0027 { 0028 JNI_OBJECT(Intent, android::content::Intent) 0029 public: 0030 /** Creates a new empty intent. */ 0031 JNI_CONSTRUCTOR(Intent) 0032 ~Intent(); 0033 0034 /** Add a category to the intent. */ 0035 JNI_METHOD(android::content::Intent, addCategory, java::lang::String) 0036 /** Add flags to this intent. */ 0037 JNI_METHOD(android::content::Intent, addFlags, jint) 0038 /** Returns the data of this intent. */ 0039 JNI_METHOD(android::net::Uri, getData) 0040 /** Get the intent action. */ 0041 JNI_METHOD(java::lang::String, getAction) 0042 /** Sets the action of the intent. */ 0043 JNI_METHOD(android::content::Intent, setAction, java::lang::String) 0044 /** Set the data URL of this intent. */ 0045 JNI_METHOD(android::content::Intent, setData, android::net::Uri) 0046 0047 /** Returns the mimetype of this intent. */ 0048 JNI_METHOD(java::lang::String, getType) 0049 /** Set the mime type for this intent. */ 0050 JNI_METHOD(android::content::Intent, setType, java::lang::String) 0051 0052 /** Read extra intent data. */ 0053 QString getStringExtra(const QJniObject &name) const; 0054 QStringList getStringArrayExtra(const QJniObject &name) const; 0055 /** Add extra intent data of type @tparam T. */ 0056 template <typename T> 0057 inline void putExtra(const QJniObject &name, const QJniObject &value) 0058 { 0059 jniHandle().callObjectMethod("putExtra", Jni::signature<android::content::Intent(java::lang::String, T)>(), name.object(), value.object()); 0060 } 0061 0062 /** Implicit conversion to an QJniObject. */ 0063 operator QJniObject() const; 0064 0065 /** Action constant for create document intents. */ 0066 JNI_CONSTANT(java::lang::String, ACTION_CREATE_DOCUMENT) 0067 /** Main activity entry point. */ 0068 JNI_CONSTANT(java::lang::String, ACTION_MAIN) 0069 /** Action constant for open document intents. */ 0070 JNI_CONSTANT(java::lang::String, ACTION_OPEN_DOCUMENT) 0071 /** Action constant for viewing intents. */ 0072 JNI_CONSTANT(java::lang::String, ACTION_VIEW) 0073 /** Share data. */ 0074 JNI_CONSTANT(java::lang::String, ACTION_SEND) 0075 /** Share multiple data items. */ 0076 JNI_CONSTANT(java::lang::String, ACTION_SEND_MULTIPLE) 0077 0078 /** Category constant for openable content. */ 0079 JNI_CONSTANT(java::lang::String, CATEGORY_OPENABLE) 0080 0081 JNI_CONSTANT(java::lang::String, EXTRA_EMAIL) 0082 JNI_CONSTANT(java::lang::String, EXTRA_STREAM) 0083 JNI_CONSTANT(java::lang::String, EXTRA_SUBJECT) 0084 JNI_CONSTANT(java::lang::String, EXTRA_TEXT) 0085 0086 /** Flag for granting read URI permissions on content providers. */ 0087 JNI_CONSTANT(jint, FLAG_GRANT_READ_URI_PERMISSION) 0088 /** Flag for granting write URI permissions on content providers. */ 0089 JNI_CONSTANT(jint, FLAG_GRANT_WRITE_URI_PERMISSION) 0090 0091 private: 0092 template <typename T> 0093 QJniObject getObjectExtra(const char* methodName, const QJniObject &name) const; 0094 }; 0095 0096 } 0097 0098 #endif // KANDROIDEXTRAS_INTENT_H