Episodex
Episodex

Reputation: 4559

How to open a file from Android content URI in NativeScript?

I'm creating import backed up data functionality for my NativeScript app. I already associated my app with custom extension and it's recognized by Android system, so if I for example click "Open with" on this file in Dropbox, I can choose my app.

I also added the code to capture the event and can retrieve the data, which is content URI of the file Dropbox sends to the app (or at least that's how I understand it).

The content URI looks like this: content://com.dropbox.android.FileCache/filecache/7b051751-3681-4ba1-8ce2-e70e8a0cae91.

I need now to open this file (which is text file with JSON). Can I do it using NativeScript classes or it must be handled with native code? How to read this file?

Upvotes: 1

Views: 924

Answers (1)

Manoj
Manoj

Reputation: 21908

Content URI is something specific to Android, so you would have to do it with native code.

I think you must be looking for getContentResolver().openInputStream(uri).

To access content resolver in {N}, you do

import * as application from "application";

const contentResolver = application.android.nativeApp.getContentResolver();

Upvotes: 1

Related Questions