我有一个使用cordova-camera-plugin
的Ionic 1应用。总体而言,它运作良好,但我遇到Android 5.x / 6.x上的应用程序崩溃问题。奇怪的是,在运行这些版本的所有设备上都不会发生这种情况。
这是ionic info
的输出:
@ionic/cli-utils : 1.19.1
ionic (Ionic CLI) : 3.19.1
global packages:
cordova (Cordova CLI) : 7.1.0
local packages:
Cordova Platforms : android 7.0.0 ios 4.5.4
Ionic Framework : ionic1 1.3.5
System:
ios-deploy : 1.9.2
Node : v8.9.4
npm : 5.6.0
OS : macOS High Sierra
Xcode : Xcode 9.2 Build version 9C40b
出于某种原因,AndroidManifest.xml
添加的唯一权限是READ_EXTERNAL_STORAGE
,因此我继续手动添加了CAMERA
和WRITE_EXTERNAL_STORAGE
。这是完整的文件:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="6032" android:versionName="1.6.0" package="com.scoutforpets.staff" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="@string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true" android:name="android.support.v4.content.FileProvider">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
</provider>
<service android:enabled="true" android:exported="false" android:name="com.google.android.gms.measurement.AppMeasurementService" />
<service android:name="org.apache.cordova.firebase.FirebasePluginMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name="org.apache.cordova.firebase.FirebasePluginInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<receiver android:name="org.apache.cordova.firebase.OnNotificationOpenReceiver" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<service android:exported="true" android:name="com.marianhello.bgloc.sync.SyncService" android:process=":sync">
<intent-filter>
<action android:name="android.content.SyncAdapter" />
</intent-filter>
<meta-data android:name="android.content.SyncAdapter" android:resource="@xml/syncadapter" />
</service>
<service android:name="com.marianhello.bgloc.sync.AuthenticatorService">
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator" android:resource="@xml/authenticator" />
</service>
<provider android:authorities="@string/content_authority" android:exported="false" android:name="com.marianhello.bgloc.sync.DummyContentProvider" android:syncable="true" />
<service android:enabled="true" android:exported="false" android:name="com.marianhello.bgloc.LocationService" />
<receiver android:enabled="true" android:exported="true" android:name="com.marianhello.bgloc.BootCompletedReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver android:exported="false" android:name="de.appplant.cordova.plugin.localnotification.TriggerReceiver" />
<receiver android:exported="false" android:name="de.appplant.cordova.plugin.localnotification.ClearReceiver" />
<activity android:exported="false" android:launchMode="singleInstance" android:name="de.appplant.cordova.plugin.localnotification.ClickActivity" android:theme="@android:style/Theme.NoDisplay" />
<receiver android:exported="false" android:name="de.appplant.cordova.plugin.notification.TriggerReceiver" />
<receiver android:exported="false" android:name="de.appplant.cordova.plugin.notification.ClearReceiver" />
<receiver android:exported="false" android:name="de.appplant.cordova.plugin.localnotification.RestoreReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<activity android:exported="false" android:launchMode="singleInstance" android:name="de.appplant.cordova.plugin.notification.ClickActivity" android:theme="@android:style/Theme.NoDisplay" />
<amazon:enable-feature android:name="com.amazon.device.messaging" android:required="false" xmlns:amazon="http://schemas.amazon.com/apk/res/android" />
<service android:exported="false" android:name="com.onesignal.ADMMessageHandler" />
<receiver android:name="com.onesignal.ADMMessageHandler$Receiver" android:permission="com.amazon.device.messaging.permission.SEND">
<intent-filter>
<action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
<action android:name="com.amazon.device.messaging.intent.RECEIVE" />
<category android:name="com.scoutforpets.staff" />
</intent-filter>
</receiver>
<activity android:name="net.hockeyapp.android.FeedbackActivity" />
<activity android:name="net.hockeyapp.android.UpdateActivity" />
<activity android:name="net.hockeyapp.android.LoginActivity" />
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.hardware.location" />
<uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE" />
<permission android:name="com.scoutforpets.staff.permission.RECEIVE_ADM_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.scoutforpets.staff.permission.RECEIVE_ADM_MESSAGE" />
</manifest>
这是我的config.xml
:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget android-versionCode="6033" id="com.scoutforpets.staff" ios-CFBundleVersion="574" version="1.6.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Scout</name>
<content src="index.html"/>
<allow-intent href="tel:*"/>
<allow-intent href="geo:*"/>
<allow-intent href="itms-apps:*"/>
<allow-intent href="market:*"/>
<allow-intent href="*://maps.apple.com/*"/>
<allow-navigation href="*://maps.apple.com/*"/>
<allow-navigation href="http://10.69.0.93:8100"/>
<preference name="DisallowOverscroll" value="true"/>
<preference name="BackupWebStorage" value="none"/>
<preference name="SplashScreen" value="screen"/>
<preference name="SplashScreenDelay" value="1000"/>
<preference name="orientation" value="portrait"/>
<preference name="android-minSdkVersion" value="16"/>
<preference name="CameraUsesGeolocation" value="true"/>
<hook src="scripts/incrementBuildNum.js" type="before_build"/>
<feature name="StatusBar">
<param name="ios-package" onload="true" value="CDVStatusBar"/>
</feature>
<feature name="Keyboard">
<param name="ios-package" onload="true" value="IonicKeyboard"/>
</feature>
<platform name="ios">
<access launch-external="yes" origin="*"/>
<preference name="deployment-target" value="9.0"/>
<icon height="57" src="resources/ios/icon/icon.png" width="57"/>
<icon height="114" src="resources/ios/icon/icon@2x.png" width="114"/>
<icon height="40" src="resources/ios/icon/icon-40.png" width="40"/>
<icon height="80" src="resources/ios/icon/icon-40@2x.png" width="80"/>
<icon height="120" src="resources/ios/icon/icon-40@3x.png" width="120"/>
<icon height="50" src="resources/ios/icon/icon-50.png" width="50"/>
<icon height="100" src="resources/ios/icon/icon-50@2x.png" width="100"/>
<icon height="60" src="resources/ios/icon/icon-60.png" width="60"/>
<icon height="120" src="resources/ios/icon/icon-60@2x.png" width="120"/>
<icon height="180" src="resources/ios/icon/icon-60@3x.png" width="180"/>
<icon height="72" src="resources/ios/icon/icon-72.png" width="72"/>
<icon height="144" src="resources/ios/icon/icon-72@2x.png" width="144"/>
<icon height="76" src="resources/ios/icon/icon-76.png" width="76"/>
<icon height="152" src="resources/ios/icon/icon-76@2x.png" width="152"/>
<icon height="167" src="resources/ios/icon/icon-83.5@2x.png" width="167"/>
<icon height="29" src="resources/ios/icon/icon-small.png" width="29"/>
<icon height="58" src="resources/ios/icon/icon-small@2x.png" width="58"/>
<icon height="87" src="resources/ios/icon/icon-small@3x.png" width="87"/>
<splash height="1136" src="resources/ios/splash/Default-568h@2x~iphone.png" width="640"/>
<splash height="1334" src="resources/ios/splash/Default-667h.png" width="750"/>
<splash height="2208" src="resources/ios/splash/Default-736h.png" width="1242"/>
<splash height="2048" src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536"/>
<splash height="1024" src="resources/ios/splash/Default-Portrait~ipad.png" width="768"/>
<splash height="960" src="resources/ios/splash/Default@2x~iphone.png" width="640"/>
<splash height="480" src="resources/ios/splash/Default~iphone.png" width="320"/>
<edit-config file="*-Info.plist" mode="merge" target="NSCameraUsageDescription">
<string>This app needs camera access to take pictures.</string>
</edit-config>
</platform>
<platform name="android">
<access origin="*"/>
<access launch-external="yes" origin="geo:*"/>
<preference name="loadUrlTimeoutValue" value="120000"/>
<icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png"/>
<icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png"/>
<icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png"/>
<icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png"/>
<icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png"/>
<icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png"/>
<splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png"/>
<splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png"/>
<splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png"/>
<splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png"/>
<splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png"/>
<splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png"/>
</platform>
<icon src="resources/android/icon/drawable-xhdpi-icon.png"/>
<engine name="android" spec="^7.0.0"/>
<engine name="ios" spec="^4.5.4"/>
<plugin name="cordova-plugin-firebase" spec="git+https://github.com/amritk/cordova-plugin-firebase.git"/>
<plugin name="cordova-plugin-mauron85-background-geolocation" spec="^2.3.3">
<variable name="ACCOUNT_TYPE" value="$PACKAGE_NAME.account"/>
<variable name="CONTENT_AUTHORITY" value="$PACKAGE_NAME"/>
<variable name="ALWAYS_USAGE_DESCRIPTION" value="This app always requires location tracking"/>
<variable name="GOOGLE_PLAY_SERVICES_VERSION" value="+"/>
<variable name="ICON" value="@mipmap/icon"/>
<variable name="SMALL_ICON" value="@mipmap/icon"/>
<variable name="ACCOUNT_NAME" value="@string/app_name"/>
<variable name="ACCOUNT_LABEL" value="@string/app_name"/>
</plugin>
<plugin name="cordova-plugin-whitelist" spec="^1.3.3"/>
<plugin name="de.appplant.cordova.plugin.local-notification" spec="^0.8.5"/>
<plugin name="ionic-plugin-keyboard" spec="^2.2.1"/>
<plugin name="onesignal-cordova-plugin" spec="^2.2.5"/>
<plugin name="cordova-plugin-statusbar" spec="^2.4.1"/>
<plugin name="cordova-plugin-splashscreen" spec="^5.0.2"/>
<plugin name="cordova-plugin-inappbrowser" spec="^2.0.2"/>
<plugin name="cordova-plugin-device" spec="^2.0.1"/>
<plugin name="cordova-plugin-hockeyapp" spec="^5.1.2"/>
<plugin name="cordova-plugin-camera" spec="^2.4.1">
<variable name="CAMERA_USAGE_DESCRIPTION" value=" "/>
<variable name="PHOTOLIBRARY_USAGE_DESCRIPTION" value=" "/>
</plugin>
</widget>
每当我在运行Android 5.x / 6.x的LG G4,G5或MotoX上加载此应用程序并点击相机按钮时,我提示:
我接受了两个并且能够拍照。一旦我击中&#34; OK&#34;在相机界面上,应用程序崩溃,我收到消息&#34;不幸的是,Scout已经停止。&#34;
查看adb日志,我发现以下情况:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=33, result=-1, data=null} to activity {com.scoutforpets.staff/com.scoutforpets.staff.MainActivity}: java.lang.SecurityException: Permission Denial: writing com.android.providers.media.MediaProvider uri content://media/external/images/media/464 from pid=30553, uid=10191
requires android.permission.WRITE_EXTERNAL_STORAGE, or grantUriPermission()
Caused by: java.lang.SecurityException: Permission Denial: writing com.android.providers.media.MediaProvider uri content://media/external/images/media/464 from pid=30553, uid=10191 requires android.permission.WRITE_EXTERNAL_STORAGE, or grantUriPermission()
从上面可以看出,我已明确将WRITE_EXTERNAL_STORAGE
权限添加到AndroidManifest.xml
文件中。
正如我之前提到的,在运行这些Android版本的所有设备上都不会发生这种情况。例如,运行6.0.1的Galaxy S7工作正常。
我真的很感激任何帮助,因为这现在绝对会让我失望!
谢谢!
答案 0 :(得分:0)
原来这与外部插件修改AndroidManifest.xml
并将WRITE_EXTERNAL_STORAGE
权限限制为SDK等级18及以下版本有关。
对于遇到类似问题的人来说,这是由HockeyApp插件引起的。
以下是相关问题:https://github.com/bitstadium/HockeySDK-Cordova/issues/100