Android Question code module work, when compile to a lib NOT??

ilan

Expert
Licensed User
Longtime User
hi

when i use my code module from activity main everything works fine (almost)
but when i compile it to a lib then it wont work.

i will explain first what the code module does. it is checking what installer has installed an app (by his packagename)

and when my packagename (the packagename that is running the code module) is something different then "b4a.example" it wont work (after i compile the code module to a lib) but when i try it with the code module it is working

this is the code module:

B4X:
Sub Class_Globals
    Private store As String
    Dim MyJavaCode As JavaObject
End Sub

Public Sub Initialize ' (Target As JavaObject)
    MyJavaCode.InitializeStatic(Application.PackageName & ".store_check")
End Sub

Public Sub notfromGoogle As Boolean
    store = MyJavaCode.RunMethod("isappfromplaystore", Array(Application.PackageName))
    If store = Null Then
        Log("*** ERROR *** could not perform check")
        Return False
    End If
    If store = "com.android.vending" Then Return False Else Return True
End Sub

Public Sub notfromGoogle2(packagename As String) As Boolean
    Dim list1 As List
    list1.Initialize
 
    Dim p As PackageManager
    list1 = p.GetInstalledPackages
 
    Dim exists As Boolean = False
 
    For i = 0 To list1.Size - 1
        If list1.Get(i) = packagename Then
            exists = True
            Exit
        End If
    Next

    If exists Then
        Dim str As String = MyJavaCode.RunMethod("isappfromplaystore", Array(packagename))
        If str = Null Then
            Log("*** ERROR *** could not perform check")
            Return False
        Else
            If str = "com.android.vending" Then Return False Else Return True
        End If     
    Else
        Log("Could not find such Packagename, make sure Packagename is correct")
        Return False
    End If
End Sub

Public Sub notfromAmazon As Boolean
    store = MyJavaCode.RunMethod("isappfromplaystore", Array(Application.PackageName)) 
    If store = Null Then
        Log("*** ERROR *** could not perform check")
        Return False
    End If 
    If store = "com.amazon.venezia" Then Return False Else Return True
End Sub

Public Sub notfromAmazon2(packagename As String) As Boolean
    Dim list1 As List
    list1.Initialize
 
    Dim p As PackageManager
    list1 = p.GetInstalledPackages
 
    Dim exists As Boolean = False
 
    For i = 0 To list1.Size - 1
        If list1.Get(i) = packagename Then
            exists = True
            Exit
        End If
    Next

    If exists Then
        Dim str As String = MyJavaCode.RunMethod("isappfromplaystore", Array(packagename))
        If str = Null Then
            Log("*** ERROR *** could not perform check")
            Return False
        Else
            If str = "com.amazon.venezia" Then Return False Else Return True
        End If         
    Else
        Log("Could not find such Packagename, make sure Packagename is correct")
        Return False
    End If
End Sub

Public Sub GetInstalledPeckageList As List
    Dim p As PackageManager
    p.GetInstalledPackages
    Return p.GetInstalledPackages
End Sub

#if JAVA
import android.content.Context;
public static String isappfromplaystore(String packageName) {
     return BA.applicationContext.getPackageManager().getInstallerPackageName(packageName);
}
#end if

now try to use it in an example where the packagename is "b4a.example"
and then change it to "anything.com"

it will work, but then when you compile it to a lib it will not work anymore ONLY with packagename "b4a.example"

what am i doing wrong?
 
Last edited:

HotShoe

Well-Known Member
Licensed User
Longtime User
I don't know the answer to your question, but I did take the liberty of creating a java lib to check if the app currently running is from an app store or not. It is attached and includes a test project and the Eclipse source code project.
 

Attachments

  • checkstore.zip
    6.7 KB · Views: 112
Upvote 0

ilan

Expert
Licensed User
Longtime User
Add some logs messages to see where the package name is incorrect.

I have erel and i even check in a loop if such package name exists so the problem is not the asked package name the problem is in the packagename of the running app.

(build configuration 》packagename)

If it is the default b4a.example then it is working but if i change it to any other packagename it is not working.

But that behavior is ONLY after i compile to lib (the code module) and try to run the code with the lib but running straight the code module is working.

The error msg is that the class was not found

main_activity_create (java line: 398)
java.lang.ClassNotFoundException: fg$CatchTheBall$store_check
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:234)
at java.lang.Class.forName(Class.java:181)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
This the error filippo get when he tried it.

(i did get that error too)


You can the discussion about the problem here: https://www.b4x.com/android/forum/threads/app-downloaded-from-google-play-or-amazon-lib.65377/
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
When i use lowercase letters for the packagename i get that error too.
Only b4a.example as packagename is working
 
Upvote 0

ilan

Expert
Licensed User
Longtime User


Ok, thank you erel, i understand now how it works.

When i compile the library i need to use the same packagename i used for compile.

And it will also work when the packagename of the running app will change?

So no need to intialize the javaobject with apllication.packagename?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…