SQLiteCantOpenDatabaseException after upgrading to Android 6 (Marshmallow) - android

I have an application in the PlayStore, and some users reported that it no longer worked after they updated their phones to android 6. The stack trace associated to the reports is the following
java.lang.RuntimeException: Unable to create application ar.com.package.android.MyApp: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4731)
at android.app.ActivityThread.-wrap1(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1415)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:571)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:269)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at com.activeandroid.Cache.openDatabase(Cache.java:106)
at com.activeandroid.Cache.initialize(Cache.java:75)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:44)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:34)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:30)
at com.activeandroid.app.Application.onCreate(Application.java:25)
at ar.com.package.android.MyApp.onCreate(MyApp.java:33)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1036)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4728)
Obviously the problem is related to ActiveAndroid (which I use in this app) not being able to open the database, but I wasn't able to reproduce the error as the conditions for it are very specific (Installing the app in a lolipop phone > updating the phone to marshmallow). A clean install on marshmallow works perfectly.
My first tought was the new permissions system in marshmallow, but as far as I tested I didn't find any problem with that. Just in case, here is the list of permissions:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
If anyone has an idea of what could the problem be, that would help me a lot.

Related

Android Pushwoosh IllegalStateException: Application does not define permission com.google.android.c2dm.permission.RECEIVE

I have a problem today. When I try to register to receive a push from Pushwoosh
Pushwoosh.getInstance().registerForPushNotifications()
It throws an exception like that
E/Pushwoosh: Exception occurred
java.lang.IllegalStateException: Application does not define permission com.google.android.c2dm.permission.RECEIVE
at com.pushwoosh.firebase.internal.registrar.a$b.a(Unknown Source:17)
at com.pushwoosh.firebase.internal.registrar.a$b.a(Unknown Source:30)
at com.pushwoosh.firebase.internal.registrar.a.checkDevice(Unknown Source:2)
at com.pushwoosh.notification.PushwooshNotificationManager.a(Unknown Source:45)
at com.pushwoosh.Pushwoosh.a(Unknown Source:23)
at com.pushwoosh.Pushwoosh.lambda$HgkxfkcfE_k-Lm_xVXJ-mTVOJ3g(Unknown Source:0)
at com.pushwoosh.-$$Lambda$Pushwoosh$HgkxfkcfE_k-Lm_xVXJ-mTVOJ3g.a(Unknown Source:6)
at com.pushwoosh.inapp.f.a.a(Unknown Source:11)
at com.pushwoosh.inapp.f.a.lambda$qCb0Pyb8Qrzu-2CtVmkrEeLg1C0(Unknown Source:0)
at com.pushwoosh.inapp.f.-$$Lambda$a$qCb0Pyb8Qrzu-2CtVmkrEeLg1C0.run(Unknown Source:6)
at android.os.Handler.handleCallback(Handler.java:900)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:219)
at android.os.HandlerThread.run(HandlerThread.java:67)
This is my Manifest
<manifest ..>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application ..> </application></manifest>
I have tried adding this line to my manifest but still not working
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
My device is a Huawei nova 7i, I have tried to settings in my battery follow this link, and still not working. So any solution?
Edit : Huawei Nova i7 no longer supportted by google service, so firebase messaging doesn't work

Android PIE SecurityException

When i changed target version to 28 i started to get SecurityException crashes when i'm trying to display notification by NotificationManager.notify() from FirebaseService.
I read behavior changes for Android 9, but adding of FOREGROUND_SERVICE permission doesn't help me. The problem occurs on devices with Android 9 only, but i can't reproduce it on Samsung S10.
here is logs:
java.lang.SecurityException:
at android.os.Parcel.createException (Parcel.java:1966)
at android.os.Parcel.readException (Parcel.java:1934)
at android.os.Parcel.readException (Parcel.java:1884)
at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag (INotificationManager.java:1653)
at android.app.NotificationManager.notifyAsUser (NotificationManager.java:429)
at android.app.NotificationManager.notify (NotificationManager.java:379)
at android.app.NotificationManager.notify (NotificationManager.java:355)
at com.example.Utils.onNotificationReceived (Utils.java:201)
at com.example.FirebaseService.onMessageReceived (FirebaseService.java:51)
at com.google.firebase.messaging.FirebaseMessagingService.zzd (FirebaseMessagingService.java:60)
at com.google.firebase.iid.zzg.run (zzg.java:4)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
at com.google.android.gms.common.util.concurrent.zza.run (zza.java:6)
at java.lang.Thread.run (Thread.java:764)
Caused by: android.os.RemoteException:
at com.android.server.am.ActivityManagerService.checkGrantUriPermissionLocked (ActivityManagerService.java:12755)
at com.android.server.am.ActivityManagerService.checkGrantUriPermission (ActivityManagerService.java:12772)
at com.android.server.notification.NotificationRecord.visitGrantableUri (NotificationRecord.java:1147)
at com.android.server.notification.NotificationRecord.calculateGrantableUris (NotificationRecord.java:1123)
at com.android.server.notification.NotificationRecord.<init> (NotificationRecord.java:208)
Manifest permissions:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
Could there be an issue in setting sound for channel from raw directory?

Security Exception for Download Manager with targetSdkVersion Below 22

I have a weird crash in Lollipopand below. I get a security Exception when trying to download a file from the server, but in devices running Marshmallow and above the app does not crash. Logcat:
Caused by: java.lang.SecurityException: need WRITE_EXTERNAL_STORAGE permission to use DESTINATION_FILE_URI: uid 10229 does not have android.permission.WRITE_EXTERNAL_STORAGE.
In App's grandle I use
targetSdkVersion 22
Will change after our first push on Google Console to target the latest sdk version, but for now this will remain to 22, so no need for run time permissions.
Furthermore, in App's Manifest we declare app's permission.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Also, the code that uses the DownloadManagerinside an AsynckTask :
try {
String dirPath = String.format("%5$s/%1$s/Resources/%2$s/%3$s/%4$s/", userID, resource.getiD(), filePackage.getiD(), language, dir.getCanonicalPath());
File makeDirs = new File(dirPath);
makeDirs.mkdirs();
} catch (Exception ex) {
ex.printStackTrace();
}
this.downloadManager = (DownloadManager) getApplicationContext().getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(url);
request.setDestinationInExternalFilesDir(getApplicationContext(), null, filePath);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN);
request.setVisibleInDownloadsUi(false);
downloadID = downloadManager.enqueue(request);
Again, this crash is observed only in Galaxy A5 with OS version 5.0.2, in an emulator running Samsung Galaxy S6 with Lollipop and in emulator running Kitkat 4.4.4 HTC One.
The full stack trace :
java.lang.RuntimeException: Unable to start activity ComponentInfo{...players.PDFViewer}: java.lang.SecurityException: need WRITE_EXTERNAL_STORAGE permission to use DESTINATION_FILE_URI: uid 10229 does not have android.permission.WRITE_EXTERNAL_STORAGE.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2808)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2873)
at android.app.ActivityThread.access$900(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6145)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.SecurityException: need WRITE_EXTERNAL_STORAGE permission to use DESTINATION_FILE_URI: uid 10229 does not have android.permission.WRITE_EXTERNAL_STORAGE.
at android.os.Parcel.readException(Parcel.java:1540)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:185)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:475)
at android.content.ContentResolver.insert(ContentResolver.java:1260)
at android.app.DownloadManager.enqueue(DownloadManager.java:1336)
at de.imsystems.crmmobile.players.PDFViewer.onCreate(PDFViewer.java:104)
at android.app.Activity.performCreate(Activity.java:6374)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2752)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2873) 
at android.app.ActivityThread.access$900(ActivityThread.java:181) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1482) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:6145) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) 
If you have any thoughts, please share them, thanks in advance.
Eventually this post WRITE_EXTERNAL_STORAGE not working on lollipop even though it's set in the manifest helped me. What I did was to alter permissions in AndroidManifest.xml file like this:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="26" tools:replace="android:maxSdkVersion"/>
This way the app doesn't crashes!

First time audio recoding permission get issue

java.lang.RuntimeException: setAudioSource failed.
11-07 20:30:16.294 12438-12438/com.main.sample W/System.err: at android.media.MediaRecorder.setAudioSource(Native Method)
11-07 20:30:16.294 12438-12438/com.main.sample W/System.err: at com.main.sample.Activity.EventsaddActivity.initializeMediaRecord
In the first step you need to add these permissions:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
set target sdk to 22 or use request permission and set target to 23 or above.
and check your path again
MediaRecorder.setAudioSource(new File("YOUR_PATH"));

Cannot get my location using the emulataor

I am trying to develop a Google Map application.
The demo application works fine on a real device but fails on the emulator.
the logcat output is as follows:
java.lang.RuntimeException: Unable to start activity ComponentInfo{il.co.talkie.mapdemo/il.co.talkie.mapdemo.MapDemoActivity}: java.lang.SecurityException: "passive" location provider requires ACCESS_FINE_LOCATION permission.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.SecurityException: "passive" location provider requires ACCESS_FINE_LOCATION permission.
at android.os.Parcel.readException(Parcel.java:1599)
at android.os.Parcel.readException(Parcel.java:1552)
at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:606)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:880)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:464)
at il.co.talkie.mapdemo.MapDemoActivity.getMyLocation(MapDemoActivity.java:170)
at il.co.talkie.mapdemo.MapDemoActivity.onCreate(MapDemoActivity.java:106)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Line 170 of MapDemoActivity is
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0,0, this);
The manifest file has these permissions (otherwise it will not work on a real device) as can be seen here:
Manifest.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="il.co.talkie.mapdemo" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<permission
android:name="com.javapapers.currentlocationinmap.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" />
<activity
android:name=".MapDemoActivity"
android:label="#string/title_activity_map_demo" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I would like to use the emulator to get my location - it displays the google map and it finds locations of addresses I provide, but it refuses to get my location - so I can not calculate distances properly.
What is wrong?
The emulator I use was created for API 23 and target Google API.
Any help will be welcomed.
If you are using emulator on Android M , you will need to request permission from user despite your manifest. See
ACCESS_FINE_LOCATION permission error emulator only
Android M Google API's to use Google Maps and other permissions
You may check out articles / tutorials e.g. this to work with the new system or just target a lower API <= 22
Error is occuring because of this problem:
Caused by: java.lang.SecurityException: "passive" location provider requires ACCESS_FINE_LOCATION permission.
Just add a new permission to your app manifest:
uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

Categories

Resources