Android Question Fire OS 5.7.1.0 and Generate Unique Id

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have this Generate Unique Id ( https://www.b4x.com/android/forum/t...oid-no-permissions-needed.128388/page-2#posts ) in my code and one of my users is using a Kindle running Fire OS 5.7.10 and he is crashing with a <code>java.lang.ClassCastException: java.lang.NoClassDefFoundError cannot be cast to java.lang.Exception</code>

Is there anyway I can notice I am on a Kindle and avoid doing the call to GetDeviceInfo

Thanks

BobVal
 

JohnC

Expert
Licensed User
Longtime User
A Try/Catch wouldn't work?

B4X:
Try
    UID = GetUniqueID 
Catch
    'do this instead if there was an error trying to do the above code
    UID = GenRandomNumber
End Try
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I have
B4X:
Public Sub  GetUniqueID As String
            Try
                Dim jo As JavaObject     = Me
                Dim ID As String         = jo.RunMethod("getUniqueID", Null)
                
                Log(ID)               
                
                Return ID               
            Catch
                Return ""
            End Try           
End Sub

#If Java
import android.media.MediaDrm;
import android.os.Build;
import android.content.*;
import java.util.*;

//private final Context context;
private String initialVal = "";


public String getUniqueID() {
   UUID wideVineUuid = new UUID(-0x121074568629b532L, -0x5c37d8232ae2de13L);
   try {
      MediaDrm wvDrm = new MediaDrm(wideVineUuid);
      byte[] wideVineId = wvDrm.getPropertyByteArray(MediaDrm.PROPERTY_DEVICE_UNIQUE_ID);
      Base64.Encoder enc = Base64.getEncoder();
      String encodedUid = enc.encodeToString(wideVineId);
      return encodedUid;
   } catch (Exception e) {
      return "";
   }
}

#End If
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
OK, ChatGPT says the below, but it's solution was confusing, so I won't post it. But basically it is saying:

The issue you're encountering seems to stem from the fact that NoClassDefFoundError and ClassCastException are not standard Exception types in Java—they are Error and RuntimeException, respectively. In Java (and B4A as well), the Catch block only catches exceptions that are instances of java.lang.Exception and not java.lang.Error.
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Going to add this code to check for Kindles before the call

B4X:
Dim InstalledFrom As String = cGenFuncs.GetInstallerPackageName  
           
            InstalledFrom = InstalledFrom.ToLowerCase
           
            If  InstalledFrom.Contains("amazon") Then              
                Log("Kindle Fire")
                Return "Kindle Fire"              
            End If
           
            Dim R                       As Reflector
           
            Dim Temp As String = r.GetStaticField("android.os.Build", "MODEL")

            If  Temp.StartsWith("KF") Then                                                  
                Log("Kindle Fire")
                               
                Return "Kindle Fire"
            End If


This should get this user up and running - don't know if I have many kindle users I'm NOT in the Amazon store
 
Upvote 0
Top