mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-02 19:12:40 +08:00
feat(android): add openFile to utils (#6895)
* feat(android): add openFile to utils * tests: move test_openFile() test to apps/ui-tests-app Small changes to openFile() method
This commit is contained in:
@ -27,6 +27,17 @@
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true" >
|
||||
<meta-data android:name="debugLayouts" android:value="true" />
|
||||
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
android:authorities="org.nativescript.apps.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/provider_paths"/>
|
||||
</provider>
|
||||
|
||||
<activity
|
||||
android:name="com.tns.NativeScriptActivity"
|
||||
android:label="@string/title_activity_kimera"
|
||||
|
||||
4
apps/app/App_Resources/Android/xml/provider_paths.xml
Normal file
4
apps/app/App_Resources/Android/xml/provider_paths.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-path name="external_files" path="."/>
|
||||
</paths>
|
||||
17
apps/app/ui-tests-app/intent/main-page.ts
Normal file
17
apps/app/ui-tests-app/intent/main-page.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { EventData } from "tns-core-modules/data/observable";
|
||||
import { SubMainPageViewModel } from "../sub-main-page-view-model";
|
||||
import { WrapLayout } from "tns-core-modules/ui/layouts/wrap-layout";
|
||||
import { Page } from "tns-core-modules/ui/page";
|
||||
|
||||
export function pageLoaded(args: EventData) {
|
||||
const page = <Page>args.object;
|
||||
const wrapLayout = <WrapLayout>page.getViewById("wrapLayoutWithExamples");
|
||||
page.bindingContext = new SubMainPageViewModel(wrapLayout, loadExamples());
|
||||
}
|
||||
|
||||
export function loadExamples() {
|
||||
const examples = new Map<string, string>();
|
||||
examples.set("open-file", "intent/open-file");
|
||||
|
||||
return examples;
|
||||
}
|
||||
6
apps/app/ui-tests-app/intent/main-page.xml
Normal file
6
apps/app/ui-tests-app/intent/main-page.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Page loaded="pageLoaded">
|
||||
<ScrollView orientation="vertical" row="1">
|
||||
<WrapLayout id="wrapLayoutWithExamples"/>
|
||||
</ScrollView>
|
||||
</Page>
|
||||
15
apps/app/ui-tests-app/intent/open-file.ts
Normal file
15
apps/app/ui-tests-app/intent/open-file.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { isIOS, isAndroid } from "tns-core-modules/platform";
|
||||
import * as fs from "tns-core-modules/file-system/file-system";
|
||||
import * as utils from "tns-core-modules/utils/utils";
|
||||
|
||||
export function openFile() {
|
||||
let directory;
|
||||
if (isIOS) {
|
||||
directory = fs.knownFolders.ios.downloads();
|
||||
} else if (isAndroid) {
|
||||
directory = android.os.Environment.getExternalStorageDirectory().getAbsolutePath().toString();
|
||||
}
|
||||
|
||||
const filePath = fs.path.join(directory, "Test_File_Open.txt");
|
||||
utils.openFile(filePath);
|
||||
}
|
||||
5
apps/app/ui-tests-app/intent/open-file.xml
Normal file
5
apps/app/ui-tests-app/intent/open-file.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<Page navigatingTo="navigatingTo">
|
||||
<GridLayout id="root">
|
||||
<Button text="Open File" tap="openFile" height="40"></Button>
|
||||
</GridLayout>
|
||||
</Page>
|
||||
@ -36,6 +36,7 @@ export function pageLoaded(args: EventData) {
|
||||
examples.set("progress-bar", "progress-bar/main-page");
|
||||
examples.set("date-picker", "date-picker/date-picker");
|
||||
examples.set("nested-frames", "nested-frames/main-page");
|
||||
examples.set("intent", "intent/main-page");
|
||||
page.bindingContext = new MainPageViewModel(wrapLayout, examples);
|
||||
|
||||
const parent = page.getViewById("parentLayout");
|
||||
|
||||
Reference in New Issue
Block a user