Changeset View
Changeset View
Standalone View
Standalone View
mobile/android/src/OpenFileActivity.java
- This file was added.
1 | package org.kde.something; | ||||
---|---|---|---|---|---|
2 | | ||||
3 | import android.content.ContentResolver; | ||||
4 | import android.content.Intent; | ||||
5 | import android.util.Log; | ||||
6 | import android.os.Bundle; | ||||
7 | import android.os.ParcelFileDescriptor; | ||||
8 | import android.net.Uri; | ||||
9 | | ||||
10 | import org.qtproject.qt5.android.bindings.QtActivity; | ||||
11 | | ||||
12 | class FileClass | ||||
13 | { | ||||
14 | public static native void openUri(String uri); | ||||
15 | } | ||||
16 | | ||||
17 | public class OpenFileActivity extends QtActivity { | ||||
18 | @Override | ||||
19 | public void onCreate(Bundle savedInstanceState) { | ||||
20 | super.onCreate(savedInstanceState); | ||||
21 | final Intent bundleIntent = getIntent(); | ||||
22 | if (bundleIntent == null) | ||||
23 | return; | ||||
24 | | ||||
25 | final String action = bundleIntent.getAction(); | ||||
26 | Uri uri = bundleIntent.getData(); | ||||
27 | if (!uri.getScheme().equals("file")) { | ||||
28 | try { | ||||
29 | ContentResolver resolver = getBaseContext().getContentResolver(); | ||||
30 | ParcelFileDescriptor fdObject = resolver.openFileDescriptor(uri, "r"); | ||||
31 | uri = Uri.parse("fd:///" + fdObject.detachFd()); | ||||
32 | } catch (Exception e) { | ||||
33 | e.printStackTrace(); | ||||
34 | | ||||
35 | //TODO: emit warning that couldn't be opened | ||||
36 | Log.v("Okular", "failed to open"); | ||||
37 | return; | ||||
38 | } | ||||
39 | } | ||||
40 | | ||||
41 | FileClass.openUri(uri.toString()); | ||||
42 | } | ||||
43 | } |