Commit 6b59328d authored by Volker Krause's avatar Volker Krause

Implement opening of documents on Android

This needs a bit more setup, so we can bypass the sandboxing and give
external apps access to our internally stored documents.
parent 25e6f36e
......@@ -95,6 +95,16 @@
<!-- auto screen scale factor -->
<meta-data android:name="android.app.auto_screen_scale_factor" android:value="true"/>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="org.kde.itinerary.documentProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
</application>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/>
......
......@@ -47,9 +47,12 @@
#include <QUrlQuery>
#ifdef Q_OS_ANDROID
#include <kandroidextras/activity.h>
#include <kandroidextras/contentresolver.h>
#include <kandroidextras/intent.h>
#include <kandroidextras/uri.h>
#include <kandroidextras/jnisignature.h>
#include <kandroidextras/jnitypes.h>
#include <QtAndroid>
#include <QAndroidJniObject>
......@@ -492,5 +495,16 @@ void ApplicationController::removeDocument(const QString &batchId, const QString
void ApplicationController::openDocument(const QUrl &url)
{
#ifdef Q_OS_ANDROID
using namespace KAndroidExtras;
auto activity = QtAndroid::androidActivity();
auto uri = activity.callObjectMethod("openDocument", Jni::signature<android::net::Uri(java::lang::String)>(), QAndroidJniObject::fromString(url.toLocalFile()).object());
Intent intent;
intent.setData(uri);
intent.setAction(Intent::ACTION_VIEW());
Activity::startActivity(intent, 0);
#else
QDesktopServices::openUrl(url);
#endif
}
......@@ -20,6 +20,7 @@ apply plugin: 'com.android.application'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'org.mnode.ical4j:ical4j:2.2.0'
implementation 'androidx.core:core:1.0.2'
}
android {
......
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="documents" path="documents/"/>
</paths>
......@@ -21,6 +21,8 @@ import org.qtproject.qt5.android.bindings.QtActivity;
import net.fortuna.ical4j.model.property.XProperty;
import androidx.core.content.FileProvider;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Intent;
......@@ -120,4 +122,11 @@ public class Activity extends QtActivity
super.onNewIntent(intent);
importFromIntent(intent);
}
public Uri openDocument(String filePath)
{
Log.i(TAG, filePath);
File file = new File(filePath);
return FileProvider.getUriForFile(this, "org.kde.itinerary.documentProvider", file);
}
}
......@@ -59,6 +59,11 @@ void Intent::setAction(const QAndroidJniObject &action)
void Intent::setData(const QUrl& url)
{
const auto uri = Uri::fromUrl(url);
setData(uri);
}
void Intent::setData(const QAndroidJniObject& uri)
{
m_intent.callObjectMethod("setData", Jni::signature<android::content::Intent(android::net::Uri)>(), uri.object());
}
......
......@@ -42,6 +42,7 @@ public:
void setAction(const QAndroidJniObject &action);
/** Set the data URL of this intent. */
void setData(const QUrl &url);
void setData(const QAndroidJniObject &uri);
/** Set the mime type for this intent. */
void setType(const QString &type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment