B4A Library App downloaded from Google Play or Amazon Lib

hi,

this is my 3rd lib. with this lib you can check if your app was downloaded from the google play store or the amazon store or from NO store and do what ever you want (like close the app or turn on self destruction :D)

now you can easily catch people that have bought your app, backed-up the apk, uninstalled it and get a refund. so no more working for free :)

note that it is not a 100% protection but at least it will be a little bit harder for people to use your paid apps for free.

the lib is very simple:

Step 1, we intialize the lib (store_check) in activity_create like this:

B4X:
Sub Activity_Create(FirstTime As Boolean)

'Intialize
    Dim check As store_check
    check.Initialize
'......

then we just check if app was downloaded from the store like this:

B4X:
    If check.notfromGoogle Then Log("this app was NOT downloaded from the google play store")  Else Log("check ok or unknow")

you may also do it (if you like) only if "Firsttime = True".

I have not tested it on an amazon app, only on google play app and it worked see attached pictures

Pic1 = installed from my PC
Pic2 = installed from Google Play

If you find any bugs please let me know, and if you like to donate me a small (or big) amount i would be very happy. :)

PS: Please make some tests before you update all your apps, i dont know if there is a minimum SDK or anything else so you use this lib on your own risk :cool:

EDIT:

Version 1.01
Version 1.02 (Bug fixed)

Version 1.03 (after @Erel has explained how to compile a code module it is now working correctly)

New Method: Check any peckagename (app) if it is installed from the Store

B4X:
    If check.notfromGoogle2("com.android.gallery") Then Log("this app was NOT downloaded from the google play store")  Else Log("check ok or unknow")

COMPLETE CODE MODULE: https://www.b4x.com/android/forum/t...e-play-or-amazon-lib.65377/page-2#post-414562

I also want to thank to @JordiCP and to @DonManfred

1.jpg
 

Attachments

  • Example.zip
    1.6 KB · Views: 440
  • Lib v1.03.zip
    4.1 KB · Views: 432
Last edited:

ilan

Expert
Licensed User
Longtime User
What is different between your Library and the Licensing Library ?

Are you doing something different with yours ?

this lib doesnot send anything or check any license, it only tells you if your app was installed from google play store or or not (works Offline/Online).

you can check for example one of my apps i have tested it on it: https://play.google.com/store/apps/details?id=www.sagitalfds.net&hl=en

if you install it through the google play store (your pc or google play app) then if you connect it to the b4a ide and click on the connect button
you will see in the logs this line: THIS APP WAS DOWNLOADED FROM GOOGLE PLAY

and then try to download a free apk backup application like: "App Backup & Restore" then backup the apk and uninstall my app. then restore the app from the
backup app and you will get in the logs "THIEF" because now the apk was not installed from google play.
it just check how the app was installed not if you are licensed to use it. it is a different check. and if i know that my apk was not installed through google play i
decide if i want to let the user keep using my app or do any action. it is also working on free apps so you can also build a statistic to check how many active users really downloaded your app through google play or through amazon...

i also dont recommend after you make the check to do any actions like closing the app i would say store a file and after a while (2 weeks maybe) warn the user that he is using a not valid copy and if he will keep using it all data will be deleted in the next days (like inline db of the app,...)

i have never user the license lib so i cannot tell you exactly what is better but what i do agree is that we need to use some protection since today it is so simple to backup an paid apk and restore it.
 
Last edited:

sorex

Expert
Licensed User
Longtime User
interesting. I didn't know it stored some kind of install path/source.

what do you get when installing over adb?

won't that prevent testing on usb or emulated devices?
 

ilan

Expert
Licensed User
Longtime User
interesting. I didn't know it stored some kind of install path/source.

yes it does

what do you get when installing over adb?

NULL

won't that prevent testing on usb or emulated devices?

no, it depends what you decide to do when the app recognize that it was not installed from the store. if you want to close the app immidiatly when from_store = false then
you can set a Boolean in your Globals named: "DEVELOPING" and if it is true it will skip that check and change it back when you build the store apk

or do it like in b4i:

#If Not Dev
'check if app was installed from store
' ....
#End if
 

ilan

Expert
Licensed User
Longtime User
Lib has been updated, no more need of a global java object just intialize and ask if app was downloaded from the store (thanx to @Informatix's explanation)

added 2 new Method. Now you can ask for any packagename if it was installed from the store so you may also check if the user has another app of you installed and if it was downloaded from the store.

download the example for more details :)
 
D

Deleted member 103

Guest
Hi ilan,

I just try your library, unfortunately it does not work so well.
I think but when it works really well then it can become a very useful library.

Do you know where the error is?
The app "fg.CatchTheBall" is installed.

B4X:
Sub Activity_Create(FirstTime As Boolean)
'Intialize
    Dim check As store_check
    check.Initialize

'Get all installed PeckageNames   
    Dim list1 As List
    list1.Initialize
   
    list1 = check.GetInstalledPeckageList
   
'    For i = 0 To list1.Size-1
'        Log(list1.Get(i))
'    Next
   
'Check if a manual peckage is installed from Google Play   
    If check.fromGoogle2("fg.CatchTheBall") Then Log("THIS APP WAS DOWNLOADED FROM GOOGLE PLAY") Else Log("THIEF") 'tested!
    'If check.fromGoogle2("www.sagitalfds.net") Then Log("THIS APP WAS DOWNLOADED FROM GOOGLE PLAY") Else Log("THIEF") 'tested!
   
'Check if THIS (sender) app is installed from Google Play
    If check.fromGoogle Then Log("THIS APP WAS DOWNLOADED FROM GOOGLE PLAY") Else Log("THIEF") 'tested!
'    If check.fromAmazon Then Log("THIS APP WAS DOWNLOADED FROM AMAZON") Else Log("THIEF") 'not tested!
End Sub

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
store_check_fromgoogle2 (java line: 145)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
at b4a.example.store_check._fromgoogle2(store_check.java:145)
at b4a.example.main._activity_create(main.java:333)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 

ilan

Expert
Licensed User
Longtime User
filippo please check that the list contains such a packagename
is it the app you are running or a different app?
 

ilan

Expert
Licensed User
Longtime User
btw it is not necessary to get the list of all installed packagenames, it is just an option.
 

ilan

Expert
Licensed User
Longtime User
ok i have downloaded your app from google play and tried to check if it was installed from google play and it is working for me

pic3.jpg
 
D

Deleted member 103

Guest
I have the app now installed by google-play.
Something is not working properly.

Tested with Nexus-7 and HTC-one-s

check_app.JPG
 
Last edited by a moderator:

ilan

Expert
Licensed User
Longtime User
is this the real app or only a test app?
try to run this example and tell me if you get an error
 

Attachments

  • test.zip
    1.7 KB · Views: 320
D

Deleted member 103

Guest
Nexus-7 = 5.1.1
HTC-one-s = 4.1.1
Here again 2 tests
 

Attachments

  • check_app_3.JPG
    check_app_3.JPG
    175.2 KB · Views: 327
  • check_app_4.JPG
    check_app_4.JPG
    186.4 KB · Views: 285

ilan

Expert
Licensed User
Longtime User
ok now it looks better (no red text)

the second pic says that an app with that packagename was not found
that means you entered a wrong packagename. the first pic shows that the app was found and it was downloaded from the google store

is it now working for you?
 

ilan

Expert
Licensed User
Longtime User
the problem is the spelling, uppercase and lowercase letters.

This is the case only for the java object intialize (class name need to be lowercase) but not for the packagename.

When i tried your example i used the same name as you did and it worked so this should not be a problem but if it worked for you only when the packagename was with lowercase letters than use it like this.
 
D

Deleted member 103

Guest
I now attempts an emulator, here is the result:
1.test
If check.fromGoogle2("fg.CatchTheBall") Then Log("THIS APP WAS DOWNLOADED FROM GOOGLE PLAY") Else Log("THIEF") 'tested!
#####################################################

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
fg.CatchTheBall
store_check_fromgoogle2 (java line: 145)
java.lang.NullPointerException
at b4a.example.store_check._fromgoogle2(store_check.java:145)
at b4a.example.main._activity_create(main.java:344)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)

2.test
If check.fromGoogle2("fg.CatchTheBall".ToLowerCase) Then Log("THIS APP WAS DOWNLOADED FROM GOOGLE PLAY") Else Log("THIEF") 'tested!
#####################################################

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
fg.CatchTheBall
Could not find such Packagename, make sure Packagename is correct
THIEF
THIEF
** Activity (main) Resume **

the output from:
B4X:
    For i = 0 To list1.Size-1
        If list1.Get(i) = "fg.CatchTheBall" Then Log(list1.Get(i))
    Next
is always "fg.CatchTheBall"
 
Top