1- import {
2- AndroidActivityResultEventData ,
3- AndroidApplication ,
4- android as androidApp ,
5- } from '@nativescript/core/application' ;
1+ import { AndroidActivityResultEventData , AndroidApplication , android as androidApp } from '@nativescript/core/application' ;
62import { File , Folder } from '@nativescript/core/file-system' ;
73
84const REQUEST_CODE = 2343 ;
@@ -14,65 +10,39 @@ export class ShareFile {
1410 const path = args . path ;
1511 const intent = new android . content . Intent ( ) ;
1612 const map = android . webkit . MimeTypeMap . getSingleton ( ) ;
17- const mimeType = map . getMimeTypeFromExtension (
18- this . fileExtension ( path )
19- ) ;
13+ const mimeType = map . getMimeTypeFromExtension ( this . fileExtension ( path ) ) ;
2014
21- intent . addFlags (
22- android . content . Intent . FLAG_GRANT_READ_URI_PERMISSION
23- ) ;
15+ intent . addFlags ( android . content . Intent . FLAG_GRANT_READ_URI_PERMISSION ) ;
2416
25- const uris = new java . util . ArrayList ( ) ;
26- const uri = this . _getUriForPath (
27- path ,
28- '/' + this . fileName ( path ) ,
29- androidApp . context
30- ) ;
31- uris . add ( uri ) ;
17+ const uri = this . _getUriForPath ( path , '/' + this . fileName ( path ) , androidApp . context ) ;
18+ // uris.add(uri);
3219 const builder = new android . os . StrictMode . VmPolicy . Builder ( ) ;
3320 android . os . StrictMode . setVmPolicy ( builder . build ( ) ) ;
3421
35- intent . setAction (
36- android . content . Intent . ACTION_SEND_MULTIPLE
37- ) ;
38- intent . setType ( 'message/rfc822' ) ;
39- intent . putParcelableArrayListExtra (
40- android . content . Intent . EXTRA_STREAM ,
41- uris
42- ) ;
22+ intent . setAction ( android . content . Intent . ACTION_SEND ) ;
23+ intent . setType ( args ?. type || '*/*' ) ;
24+ intent . putExtra ( android . content . Intent . EXTRA_STREAM , uri ) ;
25+ // intent.putParcelableArrayListExtra(
26+ // android.content.Intent.EXTRA_STREAM,
27+ // uris
28+ // );
4329
44- const activity =
45- androidApp . foregroundActivity ||
46- androidApp . startActivity ;
30+ const activity = androidApp . foregroundActivity || androidApp . startActivity ;
4731
48- const onActivityResultHandler = (
49- data : AndroidActivityResultEventData
50- ) => {
51- androidApp . off (
52- AndroidApplication . activityResultEvent ,
53- onActivityResultHandler
54- ) ;
32+ const onActivityResultHandler = ( data : AndroidActivityResultEventData ) => {
33+ androidApp . off ( AndroidApplication . activityResultEvent , onActivityResultHandler ) ;
5534 if ( data . requestCode === REQUEST_CODE ) {
5635 resolve ( data . resultCode ) ;
5736 }
5837 } ;
59- androidApp . on (
60- AndroidApplication . activityResultEvent ,
61- onActivityResultHandler
62- ) ;
38+ androidApp . on ( AndroidApplication . activityResultEvent , onActivityResultHandler ) ;
6339 // activity.startActivityForResult(
6440 // new android.content.Intent(
6541 // android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS
6642 // ),
6743 // 0
6844 // );
69- activity . startActivityForResult (
70- android . content . Intent . createChooser (
71- intent ,
72- args . title || 'Open file:'
73- ) ,
74- REQUEST_CODE
75- ) ;
45+ activity . startActivityForResult ( android . content . Intent . createChooser ( intent , args . title || 'Open file:' ) , REQUEST_CODE ) ;
7646 } catch ( e ) {
7747 reject ( e ) ;
7848 }
@@ -125,11 +95,7 @@ export class ShareFile {
12595 const localFileContents = localFile . readSync ( function ( e ) {
12696 console . log ( e ) ;
12797 } ) ;
128- let cacheFileName = this . _writeBytesToFile (
129- ctx ,
130- fileName ,
131- localFileContents
132- ) ;
98+ let cacheFileName = this . _writeBytesToFile ( ctx , fileName , localFileContents ) ;
13399 if ( cacheFileName . indexOf ( 'file://' ) === - 1 ) {
134100 cacheFileName = 'file://' + cacheFileName ;
135101 }
@@ -173,10 +139,7 @@ export class ShareFile {
173139 }
174140 }
175141 toStringArray ( arg ) {
176- const arr = java . lang . reflect . Array . newInstance (
177- java . lang . String . class ,
178- arg . length
179- ) ;
142+ const arr = java . lang . reflect . Array . newInstance ( java . lang . String . class , arg . length ) ;
180143 for ( let i = 0 ; i < arg . length ; i ++ ) {
181144 arr [ i ] = arg [ i ] ;
182145 }
0 commit comments