How can I get address information using latitude and longitude? - android

I made this tutorial for get user's address and location but I got error when I changed AVD's location. When I didn't call getCityName function at getLastLocation function, I can get user's location but when I call it, it gave that error. How can I solve it?
it was give an error which was :
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.slidework3, PID: 15792
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Caused by: java.io.IOException: grpc failed
at android.location.Geocoder.getFromLocation(Geocoder.java:136)
at com.example.slidework3.AdresPage.getCityName(AdresPage.kt:152)
at com.example.slidework3.AdresPage.access$getCityName(AdresPage.kt:20)
at com.example.slidework3.AdresPage$getLastLocation$1.onComplete(AdresPage.kt:66)
at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
Edit:
I tried real device, location services working well I can get city name, street name etc. But in simulator it was give error again. I tried to change AVD's location after that it was going to crash. I believe solution is simple but I don't know how can I search this situation.

Try run the operation in a new Thread, and then if I need to update some UI view I'll do it on runOnUiThread.
https://developer.android.com/training/location/display-address#java

Related

Jetpack Compose: AccessibilityInteractionController.java exception

I released my app to Google Play and I can see a lot of fatal exceptions being logged to crashlytics, the stack trace is:
Fatal Exception: java.lang.NullPointerException
at androidx.compose.ui.node.DelegatableNodeKt.requireCoordinator-64DMado(DelegatableNodeKt.java:295)
at androidx.compose.ui.semantics.SemanticsNode.findCoordinatorToGetBounds$ui_release(SemanticsNode.kt:356)
at androidx.compose.ui.semantics.SemanticsNode.getSize-YbymL2g(SemanticsNode.java:115)
at androidx.compose.ui.platform.AndroidComposeViewAccessibilityDelegateCompat.performActionHelper(AndroidComposeViewAccessibilityDelegateCompat.java:1358)
at androidx.compose.ui.platform.AndroidComposeViewAccessibilityDelegateCompat.access$performActionHelper(AndroidComposeViewAccessibilityDelegateCompat.java:117)
at androidx.compose.ui.platform.AndroidComposeViewAccessibilityDelegateCompat$MyNodeProvider.performAction(AndroidComposeViewAccessibilityDelegateCompat.android.kt:2451)
at android.view.AccessibilityInteractionController.performAccessibilityActionUiThread(AccessibilityInteractionController.java:612)
at android.view.AccessibilityInteractionController.-wrap6(AccessibilityInteractionController.java)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1228)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6942)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
or
Fatal Exception: java.lang.NullPointerException
at androidx.compose.ui.node.DelegatableNodeKt.requireCoordinator-64DMado(DelegatableNodeKt.java:295)
at androidx.compose.ui.semantics.SemanticsNode.findCoordinatorToGetBounds$ui_release(SemanticsNode.kt:356)
at androidx.compose.ui.semantics.SemanticsNode.getSize-YbymL2g(SemanticsNode.java:115)
at androidx.compose.ui.platform.AndroidComposeViewAccessibilityDelegateCompat.performActionHelper(AndroidComposeViewAccessibilityDelegateCompat.java:1358)
at androidx.compose.ui.platform.AndroidComposeViewAccessibilityDelegateCompat.access$performActionHelper(AndroidComposeViewAccessibilityDelegateCompat.java:117)
at androidx.compose.ui.platform.AndroidComposeViewAccessibilityDelegateCompat$MyNodeProvider.performAction(AndroidComposeViewAccessibilityDelegateCompat.android.kt:2451)
at android.view.AccessibilityInteractionController.performAccessibilityActionUiThread(AccessibilityInteractionController.java:708)
at android.view.AccessibilityInteractionController.access$500(AccessibilityInteractionController.java:67)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1327)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6704)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:916)
that's all I can see in the logs.. As you can see, the stacktrace does not have any code that belongs to my app, so there's no place where I can put a try/catch for example and I can't even reproduce this.
Any idea on how to fix this or at least reproduce the issue?
This app release was built with compose v1.3, but I could see logs from 1.3-beta as well...
Any help would be appreciated.
The following release(s) address this bug.
androidx.compose.ui:ui:1.4.0-alpha05
Source: https://issuetracker.google.com/issues/258907850

Exception when running instrumented tests with Hilt and App Startup

I am starting to setup some instrumented tests on my project, but when I run them, I get the following exception on logcat:
2022-04-11 10:41:09.352 24409-24409/com.example.appstartupinstrumentationtest E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.appstartupinstrumentationtest, PID: 24409
java.lang.RuntimeException: Unable to get provider androidx.startup.InitializationProvider: androidx.startup.StartupException: java.lang.IllegalStateException: The component was not created. Check that you have added the HiltAndroidRule.
at android.app.ActivityThread.installProvider(ActivityThread.java:8195)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:7726)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7546)
at android.app.ActivityThread.access$1500(ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8633)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: androidx.startup.StartupException: java.lang.IllegalStateException: The component was not created. Check that you have added the HiltAndroidRule.
at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:162)
at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:198)
at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:38)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2429)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2399)
at android.app.ActivityThread.installProvider(ActivityThread.java:8190)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:7726) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7546) 
at android.app.ActivityThread.access$1500(ActivityThread.java:301) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:246) 
at android.app.ActivityThread.main(ActivityThread.java:8633) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) 
Caused by: java.lang.IllegalStateException: The component was not created. Check that you have added the HiltAndroidRule.
at dagger.hilt.internal.Preconditions.checkState(Preconditions.java:83)
at dagger.hilt.android.internal.testing.TestApplicationComponentManager.generatedComponent(TestApplicationComponentManager.java:96)
at dagger.hilt.android.testing.HiltTestApplication.generatedComponent(HiltTestApplication.java:49)
at dagger.hilt.EntryPoints.get(EntryPoints.java:59)
at dagger.hilt.android.EntryPointAccessors.fromApplication(EntryPointAccessors.kt:35)
at com.example.appstartupinstrumentationtest.InitializerEntryPoint$Companion.resolve(InitializerEntryPoint.kt:20)
at com.example.appstartupinstrumentationtest.SomeComponentInitializer.create(SomeComponentInitializer.kt:10)
at com.example.appstartupinstrumentationtest.SomeComponentInitializer.create(SomeComponentInitializer.kt:7)
at androidx.startup.AppInitializer.doInitialize(AppInitializer.java:155)
at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:198) 
at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:38) 
at android.content.ContentProvider.attachInfo(ContentProvider.java:2429) 
at android.content.ContentProvider.attachInfo(ContentProvider.java:2399) 
at android.app.ActivityThread.installProvider(ActivityThread.java:8190) 
at android.app.ActivityThread.installContentProviders(ActivityThread.java:7726) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7546) 
at android.app.ActivityThread.access$1500(ActivityThread.java:301) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:246) 
at android.app.ActivityThread.main(ActivityThread.java:8633) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
My real codebase is much more complex, but I created a much simpler project where I am able to reproduce the issue HERE.
From what I understood, when running the instrumentation tests, the startup code is first executed, even before anything on the test class (before #Before and #BeforeClass methods).
What is the best way to handle this?

Android 10+ android.permission.NETWORK_STACK for hidden api

I am testing a new app on a physical device:
REDMI NOTE 9 PRO
android 10
MIUI 12
I am trying to access to startSoftAp that is a hidden method of WifiManager class. That is I want programmatically start and stop tethering.
Following this approach and many other links such as:
https://www.xda-developers.com/android-development-bypass-hidden-api-restrictions/
https://www.reddit.com/r/androiddev/comments/deyz14/apparently_you_can_destroy_hidden_api_blacklist/
I am facing a new issue regarding
android.permission.NETWORK_STACK
that I am not able to fix. The main cause is
Caused by: **java.lang.SecurityException: WifiService: Neither user
10448 nor current process has android.permission.NETWORK_STACK.
Obviously I tried to specify this via manifest file but this is a non-SDK permission or hidden permission. Then them method described by many programmer to bypass hidden API seems is missing something about this permission.
Here is the stack trace.
**java.lang.reflect.InvocationTargetException**
at java.lang.reflect.Method.invoke(Native Method)
at com.example.tel_info.MainActivity.setHotspot(MainActivity.java:111)
at com.example.tel_info.MainActivity.onCreate(MainActivity.java:85)
at android.app.Activity.performCreate(Activity.java:7893)
at android.app.Activity.performCreate(Activity.java:7880)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3283)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3457)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5372)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5280)
at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2044)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7562)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.example.tel_info.HideClass.startSoftApInstance(HideClass.java:42)
Caused by: **java.lang.SecurityException: WifiService: Neither user 10448 nor current process has android.permission.NETWORK_STACK.**
at android.os.Parcel.createException(Parcel.java:2074)
at android.os.Parcel.readException(Parcel.java:2042)
at android.os.Parcel.readException(Parcel.java:1990)
at android.net.wifi.IWifiManager$Stub$Proxy.startSoftAp(IWifiManager.java:3031)
at android.net.wifi.WifiManager.startSoftAp(WifiManager.java:2721)
Caused by: android.os.RemoteException: Remote stack trace:
at android.app.ContextImpl.enforce(ContextImpl.java:1906)
at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1934)
at com.android.server.wifi.WifiServiceImpl.enforceNetworkStackPermission(WifiServiceImpl.java:915)
at com.android.server.wifi.WifiServiceImpl.startSoftAp(WifiServiceImpl.java:1206)
at android.net.wifi.IWifiManager$Stub.onTransact(IWifiManager.java:1359)
How to grant this to my app? Thanks in advance.

Cannot connect to android.support.test.orchestrator.OrchestratorService

Not able to run instrumentation test with android orchestrator,
I have followed developer doc and made same changes but it's not working.
Screen shot and logs are attached.
Any help would be appreciated thanks in advance
Logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ctpl.myinstrumentationtest, PID: 6608
java.lang.RuntimeException: Exception thrown in onCreate() of ComponentInfo{com.example.ctpl.myinstrumentationtest.test/android.support.test.runner.AndroidJUnitRunner}: java.lang.RuntimeException: Cannot connect to android.support.test.orchestrator.OrchestratorService
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5868)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.RuntimeException: Cannot connect to android.support.test.orchestrator.OrchestratorService
at android.support.test.orchestrator.instrumentationlistener.OrchestratedInstrumentationListener.connect(OrchestratedInstrumentationListener.java:87)
at android.support.test.runner.AndroidJUnitRunner.onCreate(AndroidJUnitRunner.java:303)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5863)
at android.app.ActivityThread.access$1100(ActivityThread.java:199) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
List item
I had the same problem but with androidx orchestrator. I was getting the same exception but the package was different:
Caused by: java.lang.RuntimeException: Cannot connect to androidx.test.orchestrator.OrchestratorService.
I have found the description of possbile root cause in this github thread. There's an iteresting discussion, but it seems that there's no general solution for this yet.
For me the problem was caused by setting the target sdk to 30 and launching the app on an android 30 emulator. So launching tests on emulator with api < 30 resolved this.

How to debug RealmMigrationNeededException on Android?

I use a realm database in my android project.
I've added a new column to my realm db which I generate out of a CSV and did the same in my entity file.
However, I now get a RealmMigrationNeededException if I start my app although I have uninstalled it before. So it seems like if my generated database and the entity file don't match.
I would like to know if it's possible to find out what exactly causes the exception. The stacktrace I get in Android Studio doesn't contain any clues which might help me to resolve the issue
FATAL EXCEPTION: main
Process: de.myCompany.myApp, PID: 5270
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x4000010 (has extras) } in de.myCompany.myApp.helper.WifiReceiver#2d683f50
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:872)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Caused by: io.realm.exceptions.RealmMigrationNeededException: RealmMigration must be provided
at io.realm.BaseRealm.migrateRealm(BaseRealm.java:589)
at io.realm.Realm.migrateRealm(Realm.java:1224)
at io.realm.Realm.migrateRealm(Realm.java:1213)
at io.realm.Realm.createInstance(Realm.java:237)
at io.realm.RealmCache.createRealmOrGetFromCache(RealmCache.java:114)
at io.realm.Realm.getInstance(Realm.java:197)
at de.myCompany.myApp.ImageDownloadController.fillDownloadStack(ImageDownloadController.java:94)
at de.myCompany.myApp.ImageDownloadController.<init>(ImageDownloadController.java:37)
at de.myCompany.myApp.ImageDownloadController.getInstance(ImageDownloadController.java:42)
at de.myCompany.myApp.helper.WifiReceiver.onReceive(WifiReceiver.java:30)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:862)
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
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:898) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Is there any proper way to debug a RealmMigrationNeededException except for trial and error?
If a RealmMigrationExceptionNeeded error happens, Realm automatically tries to trigger any configured migration to fix it. If no such RealmMigration exists, you instead get another RealmMigrationNeededException that overrides the underlying cause.
The fix is to just provide a dummy RealmMigration to see the real error.
I can see why it can be a bit confusing, and we should probably consider throwing a better exception message that also include the underlying cause.

Categories

Resources