while calling the function
private fun requestBatteryIgnore(){
try {
val batteryOptInt =
Intent().setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)
.setData(Uri.parse("package:" + requireContext().packageName))
startActivity(batteryOptInt)
}catch (e: java.lang.Exception){
Log.e("_error", "requestBatteryIgnore: ", e)
}
}
Getting following exception.
Stack trace:
2023-02-01 14:46:35.067 4537-4537/com.example.miles E/_error: requestBatteryIgnore:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS dat=package: }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2200)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1839)
at android.app.Activity.startActivityForResult(Activity.java:5471)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:712)
at android.app.Activity.startActivityForResult(Activity.java:5429)
at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:693)
at android.app.Activity.startActivity(Activity.java:5927)
at androidx.core.content.ContextCompat$Api16Impl.startActivity(ContextCompat.java:830)
at androidx.core.content.ContextCompat.startActivity(ContextCompat.java:279)
at androidx.fragment.app.FragmentHostCallback.onStartActivityFromFragment(FragmentHostCallback.java:167)
at androidx.fragment.app.Fragment.startActivity(Fragment.java:1445)
at androidx.fragment.app.Fragment.startActivity(Fragment.java:1433)
at com.example.miles.BlankFragment.requestBatteryIgnore(BlankFragment.kt:196)
at com.example.miles.BlankFragment.onOptionsItemSelected(BlankFragment.kt:244)
at androidx.fragment.app.Fragment.performOptionsItemSelected(Fragment.java:3263)
at androidx.fragment.app.FragmentManager.dispatchOptionsItemSelected(FragmentManager.java:3065)
at androidx.fragment.app.Fragment.performOptionsItemSelected(Fragment.java:3267)
at androidx.fragment.app.FragmentManager.dispatchOptionsItemSelected(FragmentManager.java:3065)
at androidx.fragment.app.FragmentManager$2.onMenuItemSelected(FragmentManager.java:476)
at androidx.core.view.MenuHostHelper.onMenuItemSelected(MenuHostHelper.java:90)
at androidx.activity.ComponentActivity.onMenuItemSelected(ComponentActivity.java:518)
at androidx.fragment.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:265)
at androidx.appcompat.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:266)
at androidx.appcompat.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:110)
at androidx.appcompat.app.AppCompatDelegateImpl.onMenuItemSelected(AppCompatDelegateImpl.java:1189)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:836)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:159)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:987)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:977)
at androidx.appcompat.widget.ActionMenuView.invokeItem(ActionMenuView.java:625)
at androidx.appcompat.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:156)
at android.view.View.performClick(View.java:7506)
at android.view.View.performClickInternal(View.java:7483)
at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
at android.view.View$PerformClick.run(View.java:29334)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Related
I am trying to make a app that can search the places with google autocomplete search in jetpack compose but when I launch the intent of the autocomplete and after writing one later app is crashing here is my code:-
My ViewModel
init {
if (!Places.isInitialized()) {
Places.initialize(context, "$API_KEY", Locale.US);
}
}
val field = listOf(Place.Field.NAME, Place.Field.LAT_LNG)
My UI
val context = LocalContext.current
val intent = Autocomplete.IntentBuilder(AutocompleteActivityMode.OVERLAY, viewModel.field).build(context)
val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if(it.resultCode == 2){
val place = Autocomplete.getPlaceFromIntent(it.data)
val latLng = place.latLng
Log.d("place LatLng: ", latLng.toString())
// move the camera position of the map
// cameraPositionState.move(CameraUpdateFactory.newLatLngZoom(lonLat, 15f))
}
}
My Logcat
FATAL EXCEPTION: main Process: com.example.trip, PID: 19245
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=988884199, result=2, data=Intent { (has extras) }} to activity {com.example.trip/com.example.trip.MainActivity}: java.lang.IllegalArgumentException: Intent expected to contain a Place, but doesn't.
at android.app.ActivityThread.deliverResults(ActivityThread.java:5015)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5056)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
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:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.IllegalArgumentException: Intent expected to contain a Place, but doesn't.
at com.google.android.libraries.places.internal.zzha.zze(com.google.android.libraries.places:places##2.6.0:1)
at com.google.android.libraries.places.internal.zzfo.zzb(com.google.android.libraries.places:places##2.6.0:3)
at com.google.android.libraries.places.widget.Autocomplete.getPlaceFromIntent(com.google.android.libraries.places:places##2.6.0:1)
at com.example.trip.ui.theme.tripSection.createTrip.CreateTripScreenKt$CreateTripScreen$2$1$launcher$1.invoke(CreateTripScreen.kt:116)
at com.example.trip.ui.theme.tripSection.createTrip.CreateTripScreenKt$CreateTripScreen$2$1$launcher$1.invoke(CreateTripScreen.kt:113)
at androidx.activity.compose.ActivityResultRegistryKt$rememberLauncherForActivityResult$1$1.onActivityResult(ActivityResultRegistry.kt:105)
at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:392)
at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:351)
at androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.java:638)
at android.app.Activity.dispatchActivityResult(Activity.java:8310)
at android.app.ActivityThread.deliverResults(ActivityThread.java:5008)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:5056)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
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:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
My gradle
//Google places api
implementation 'com.google.android.libraries.places:places:2.6.0'
I'm currently using flutter_logs for logging. For some reason I get a PlatformException when trying to set the meta info using the setMetaInfo function like this:
await FlutterLogs.setMetaInfo(
appId: PackageInfo.packageName,
appName: PackageInfo.appName,
appVersion: PackageInfo.version,
);
The PackageInfo class is part of package_info_plus package.
This is the error trace:
PlatformException (PlatformException(error, empty String, null, java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at com.flutter.logs.plogs.flutter_logs.LogsHelper.setupForELKStack(LogsHelper.kt:156)
at com.flutter.logs.plogs.flutter_logs.FlutterLogsPlugin$Companion.setUpPluginMethods$lambda-0(FlutterLogsPlugin.kt:150)
at com.flutter.logs.plogs.flutter_logs.FlutterLogsPlugin$Companion.$r8$lambda$KCO-SFXW70ZXiuPV_Lwf9VhDIMM(Unknown Source:0)
at com.flutter.logs.plogs.flutter_logs.FlutterLogsPlugin$Companion$$ExternalSyntheticLambda0.onMethodCall(Unknown Source:2)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319)
at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
))
How am I able to fix this?
I am creating an simple app where user types any address and gets suggestions, after clicking on any suggestion it will be displayed in a textview.
Autcomplete initialization:
try {
val fields = listOf(
Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG,
Place.Field.ADDRESS)
val intent=Autocomplete.IntentBuilder(AutocompleteActivityMode.FULLSCREEN, fields).build(this)
startActivityForResult(intent, PLACE_AUTOCOMPLETE_REQUEST_CODE)
}catch (e: Exception){
e.printStackTrace()
}
onActivityResult() code:
if (requestCode == PLACE_AUTOCOMPLETE_REQUEST_CODE){
val place = Autocomplete.getPlaceFromIntent(data!!)
et_location.setText(place.address)
mLatitude=place.latLng!!.latitude
mLongitude=place.latLng!!.longitude
}
The problem is that whenever I type a single alphabet in the Autocomplete, the application crashes saying Intent expected to contain a Place, but doesn't.
What is the problem with my code?
This question didn't help me as I want place.address to return a string address.
logcat:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=3, result=2, data=Intent { (has extras) }} to activity {com.example.happyplaces/com.example.happyplaces.activities.AddHappyPlaceActivity}: java.lang.IllegalArgumentException: Intent expected to contain a Place, but doesn't.
at android.app.ActivityThread.deliverResults(ActivityThread.java:4268)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
at android.app.ActivityThread.-wrap19(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.IllegalArgumentException: Intent expected to contain a Place, but doesn't.
at com.google.android.libraries.places.internal.zzft.zza(com.google.android.libraries.places:places##2.4.0:5)
at com.google.android.libraries.places.internal.zzeg.zza(com.google.android.libraries.places:places##2.4.0:3)
at com.google.android.libraries.places.widget.Autocomplete.getPlaceFromIntent(com.google.android.libraries.places:places##2.4.0:2)
at com.example.happyplaces.activities.AddHappyPlaceActivity.onActivityResult(AddHappyPlaceActivity.kt:253)
at android.app.Activity.dispatchActivityResult(Activity.java:7276)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4264)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
at android.app.ActivityThread.-wrap19(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
I'm trying to know when the animation close of the softkeyboard is done. So i try to use this function :
val rootLayout = findViewById<ConstraintLayout>(R.id.root_layout)
rootLayout.setWindowInsetsAnimationCallback(object : WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) {
override fun onProgress(insets: WindowInsets, runningAnimations: MutableList<WindowInsetsAnimation>): WindowInsets {
//TODO("Not yet implemented")
return insets
}
override fun onEnd(animation: WindowInsetsAnimation) {
super.onEnd(animation)
val showingKeyboard = rootLayout.rootWindowInsets.isVisible(WindowInsets.Type.ime())
if (!showingKeyboard) {
println("Keyboard is now closed")
}
}
})
but when i launch the app on my phone (and several emu) i have to face to this error :
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/view/WindowInsetsAnimation$Callback;
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1251)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3222)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3459)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2046)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:225)
at android.app.ActivityThread.main(ActivityThread.java:7564)
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.ClassNotFoundException: Didn't find class "android.view.WindowInsetsAnimation$Callback" on path: DexPathList[[zip file "/data/app/com.example.buginsetsanimationlistener-wRvK7cMTAxdBF1RCG19tlA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.buginsetsanimationlistener-wRvK7cMTAxdBF1RCG19tlA==/lib/arm64, /system/lib64, /system/product/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:230)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1251)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3222)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3459)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2046)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:225)
at android.app.ActivityThread.main(ActivityThread.java:7564)
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)
I don't understand what i should do, thanks for your answers !
I finally found my mystake. this method is for API 30+. But i've found another way to achieve my goal :
This is work when i close by myself the soft keyboard.
imm.hideSoftInputFromWindow(rootLayout.windowToken, 0, object : ResultReceiver(null) {
override fun onReceiveResult(resultCode: Int, resultData: Bundle?) {
if (resultCode == InputMethodManager.RESULT_UNCHANGED_HIDDEN ||
resultCode == InputMethodManager.RESULT_HIDDEN) {
//Soft has finished the animation
}
}
}
})
Hope this answer help someone :)
i am using firebase auth to login a user anonymously in my app and i want to handle the exception manually.The condition is when the sign is not completed it will throw a exception.But whenever i am running the app its just crash
Calling login method from Respository class
fun login(mobno: String, passwrod: String) {
auth.signInAnonymously().addOnCompleteListener {
if(!it.isSuccessful){
throw TypeMismatchedException(it.exception!!.message.toString())
}
}
Handling exception from Viewmodelclass
fun login(mobno:String,password:String){
try {
repo.login(mobno,password)
}catch (e:TypeMismatchedException){
Log.d("exc",e.message)
}
catch (e: FirebaseAuthException){
Log.d("exc",e.message)
}
}
Logcat
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:35)
at com.android.internal.os.ZygoteInit.main(Unknown Source:275)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:11)
at com.android.internal.os.ZygoteInit.main(Unknown Source:275)
Caused by: com.smartme.student.TypeMismatchedException: This operation is restricted to administrators only.
at com.smartme.student.viewmodel.Respository$login$1.onComplete(Respository.kt:18)
at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
at android.os.Handler.handleCallback(Unknown Source:2)
at android.os.Handler.dispatchMessage(Unknown Source:4)
at android.os.Looper.loop(Unknown Source:242)
at android.app.ActivityThread.main(Unknown Source:98)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(Unknown Source:11)
at com.android.internal.os.ZygoteInit.main(Unknown Source:275)