我一直在尝试在Android文件系统中读取文件或写入文件。我的项目是在AngularJS中开发的,并使用Cordova将其转换为APK。当我安装应用程序时,它不要求文件系统权限,也不能读取或写入文件。它可以在IDE中工作,但不能在移动的中工作。解决方案是什么?
bakd9h0s1#
您应该针对WRITE_EXTERNAL_STORAGE和READ_EXTERNAL_STORAGE呼叫checkPermission和requestPermissions。
import { AndroidPermissions } from '@awesome-cordova-plugins/android-permissions/ngx'; constructor(private androidPermissions: AndroidPermissions) { } this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE).then( result => console.log('Has permission?',result.hasPermission), err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE) ); this.androidPermissions.requestPermissions([this.androidPermissions.PERMISSION.READ_EXTERNAL_STORAGE, this.androidPermissions.PERMISSION.WRITE_EXTERNAL_STORAGE]);
请参阅https://github.com/NeoLSN/cordova-plugin-android-permissions
1条答案
按热度按时间bakd9h0s1#
您应该针对WRITE_EXTERNAL_STORAGE和READ_EXTERNAL_STORAGE呼叫checkPermission和requestPermissions。
请参阅https://github.com/NeoLSN/cordova-plugin-android-permissions