Android Question Check android version before app initialize?

Discussion in 'Android Questions' started by HAH, Aug 5, 2018.

  1. HAH

    HAH Active Member Licensed User

    Hi, How to Check android version before app initialize and crash in old android versions?
     
  2. npsonic

    npsonic Member Licensed User

    Check minSdkVersion and targetSdkVersion from manifest.

    Project > Manifest Editor
    Row 5: <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>
     
  3. HAH

    HAH Active Member Licensed User

    I meant check programmatically before application initialized (not in activity create)
     
  4. KMatle

    KMatle Expert Licensed User

    Via phone lib:

    Code:
    If p.sdkversion >=23 Then ...
     
  5. HAH

    HAH Active Member Licensed User

    But where i can call it?
    application with old android version crashes before reach activity create!
     
  6. DonManfred

    DonManfred Expert Licensed User

    It crashes with which errormessage???
     
  7. HAH

    HAH Active Member Licensed User

    Unfortunately your app has stopped
    It appears before anything start! I know the error is because old android versions (in new one it works fine)
     
  8. DonManfred

    DonManfred Expert Licensed User

    - NO NEED to write everything in bold!

    Connect your device with usb and usb-debugging enabled and post the log. Maybe the unfiltered log from logcat.

    In fact there IS a log. Without positing it it is hard to give any advices.

    I don´t plan to give any more answer here
     
    Mahares likes this.
  9. npsonic

    npsonic Member Licensed User

    I don't understand why you can't just modify minSdkVersion.
    If your app doesn't work with the older sdks you should set it correctly from manifest.
     
  10. KMatle

    KMatle Expert Licensed User

    The question was how to check the version at runtime. However. Please use the search function how to use the phone library or search for "p.sdkversion" to see examples.

    If errors occur, we need to see the exception message (via logs). And yes... There are always messages in the logs. Get used to check those messages to know what went wrong. If you get online with your app, you get exactly those messages from Google. So no magic here.
     
  11. HAH

    HAH Active Member Licensed User

    that it is
    I want to check before app started
     
  12. ivan.tellez

    ivan.tellez Active Member Licensed User

    Without starting your app, borrow the phone, go to settings, About the phone, Software info, And check the Android Version. Or somehow ask the user to do it.


    After the app is launched, you have the aswer in poast #4. Yo can put that in the starter service. But KMatle is right, if you dont know what is the error or what causes, there is no point on ksnowinf the android version.
     
    Last edited: Aug 5, 2018
  13. HAH

    HAH Active Member Licensed User

    Today i got old android version phone, the debug log is:
    Code:
    ** Service (firebasemessaging) Start **
    Error occurred on line: 
    27 (FirebaseMessaging)
    java.lang.NullPointerException: Attempt 
    to invoke virtual method 'com.google.android.gms.tasks.Task com.google.firebase.iid.FirebaseInstanceId.zza(java.lang.String)' on a null object reference
        at com.google.firebase.messaging.FirebaseMessaging.subscribeToTopic(Unknown Source)
        at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:
    130)
        at com.yemenet.aloo.firebasemessaging._subscribetotopics(firebasemessaging.java:
    210)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at anywheresoftware.b4a.shell.Shell.runMethod(
    Shell.java:735)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:357)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:260)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    144)
        at anywheresoftware.b4a.BA$
    2.run(BA.java:365)
        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:
    5912)
        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:
    1405)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    1200)
     
  14. HAH

    HAH Active Member Licensed User

    I need to check version before crash error
     
  15. ivan.tellez

    ivan.tellez Active Member Licensed User

    You can check in starter service

    And again, if you just want to check version to say that the app is not compatible, just change the android:minSdkVersion in the manifest.
     
  16. tigrot

    tigrot Well-Known Member Licensed User

    And if error happens before any user code execution(app init) you are not able to do anything useful. Use manifest...
     
  17. HAH

    HAH Active Member Licensed User

    Google play publish new roles not accepting older sdk, So I can't lower sdk version!
     
  18. HAH

    HAH Active Member Licensed User

    This is what i need .. How to do check version compatibility in manifest?
     
  19. npsonic

    npsonic Member Licensed User

    Check my first answer. You have to set higher min sdk value. There is no other way.
     
  20. tigrot

    tigrot Well-Known Member Licensed User

    You cannot check. You can only forbid installation on former Android versions
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice