@@ -7,14 +7,17 @@ import * as platform from "tns-core-modules/platform/platform";
77import * as permissions from "nativescript-permissions" ;
88
99let REQUEST_IMAGE_CAPTURE = 3453 ;
10+ declare let global : any ;
11+
12+ let useAndroidX = function ( ) {
13+ return global . androidx && global . androidx . appcompat ;
14+ } ;
15+ const FileProviderPackageName = useAndroidX ( ) ? global . androidx . core . content : android . support . v4 . content ;
1016
1117export let takePicture = function ( options ?) : Promise < any > {
1218 return new Promise ( ( resolve , reject ) => {
1319 try {
14- if ( ( < any > android . support . v4 . content . ContextCompat ) . checkSelfPermission (
15- applicationModule . android . context ,
16- ( < any > android ) . Manifest . permission . CAMERA ) !== android . content . pm . PackageManager . PERMISSION_GRANTED ) {
17-
20+ if ( ! permissions . hasPermission ( android . Manifest . permission . CAMERA ) ) {
1821 reject ( new Error ( "Application does not have permissions to use Camera" ) ) ;
1922
2023 return ;
@@ -36,9 +39,7 @@ export let takePicture = function (options?): Promise<any> {
3639 shouldKeepAspectRatio = types . isNullOrUndefined ( options . keepAspectRatio ) ? shouldKeepAspectRatio : options . keepAspectRatio ;
3740 }
3841
39- if ( ( < any > android . support . v4 . content . ContextCompat ) . checkSelfPermission (
40- applicationModule . android . context ,
41- ( < any > android ) . Manifest . permission . WRITE_EXTERNAL_STORAGE ) !== android . content . pm . PackageManager . PERMISSION_GRANTED ) {
42+ if ( ! permissions . hasPermission ( android . Manifest . permission . WRITE_EXTERNAL_STORAGE ) ) {
4243
4344 saveToGallery = false ;
4445 }
@@ -62,7 +63,7 @@ export let takePicture = function (options?): Promise<any> {
6263
6364 let sdkVersionInt = parseInt ( platform . device . sdkVersion ) ;
6465 if ( sdkVersionInt >= 21 ) {
65- tempPictureUri = ( < any > android . support . v4 . content ) . FileProvider . getUriForFile (
66+ tempPictureUri = FileProviderPackageName . FileProvider . getUriForFile (
6667 applicationModule . android . context ,
6768 applicationModule . android . nativeApp . getPackageName ( ) + ".provider" , nativeFile ) ;
6869 } else {
@@ -169,20 +170,20 @@ export let isAvailable = function () {
169170
170171export let requestPermissions = function ( ) {
171172 return permissions . requestPermissions ( [
172- ( < any > android ) . Manifest . permission . WRITE_EXTERNAL_STORAGE ,
173- ( < any > android ) . Manifest . permission . CAMERA
173+ android . Manifest . permission . WRITE_EXTERNAL_STORAGE ,
174+ android . Manifest . permission . CAMERA
174175 ] ) ;
175176} ;
176177
177178export let requestPhotosPermissions = function ( ) {
178179 return permissions . requestPermissions ( [
179- ( < any > android ) . Manifest . permission . WRITE_EXTERNAL_STORAGE ,
180+ android . Manifest . permission . WRITE_EXTERNAL_STORAGE ,
180181 ] ) ;
181182} ;
182183
183184export let requestCameraPermissions = function ( ) {
184185 return permissions . requestPermissions ( [
185- ( < any > android ) . Manifest . permission . CAMERA
186+ android . Manifest . permission . CAMERA
186187 ] ) ;
187188} ;
188189
0 commit comments