How to protect my “Android Apk” with a Password

Gottrik

Member
Licensed User
Longtime User
With B4ppc and a Windows Mobile Device I use the following procedure:

First, I read the Device ID:

c$ = Hardware.GetDeviceID

I modify the ID:

c$ = StrRemove(c$,6,StrLength(c$)-6) 'I use the first 8 characters

I transform the ID from Hex to Dec:

Codice = n.HexToDec (c$) ' I transform from Hex to Dec

I assign the Password value (using “ k ” and “ m ”) and I transform it from Dec to Hex:

Password = n.DecToHex(Int((Codice / k ) + m ))

With a Text Edit ( Notepad.exe) I create the Pwd.txt file and I write the Password in the first line ...
I distribute my Windows Mobile application with the Pwd.txt file ( in the same directory )
When my programm starts, it searchs for Pwd.txt file ...
and reads the “ Rpwd “ string ...

FileOpen (c1,"Pwd.txt",cRead,,cASCII)
Rpwd = FileRead (c1)
FileClose (c1)

If the Rpwd value is equal to Password value , my Apk works normally
Otherwise my Apk stops :

If Rpwd <> Password Then
Msgbox ( “Please send this code : “ & Codice & “ to ........... and you will have your Password “) ‘Apk stops
Else
DatiInput.Show ‘ Apk starts
End If

Now, my questions are :

How can I follow the above procedure but with B4Android ?
Is it possible to read the Device ID ?
How can I create a file in the Android Device root ?
I would like to distribute my Android Apk and after that I will send the “Pwd.txt” file containing the correct Password for any device ...

Have you any suggestions for me?
Thanks
Gottrik
 

TDowdeswell

Member
Licensed User
Longtime User
Device ID/ IMEI No?

See the Files tutorial: Text files
About the id:
B4X:
    Dim p As Phone
    Dim id As String
    id = p.GetDeviceId
Make sure to add a reference to the Phone library in the Libs tab.

I've just upgraded to 1.6 and this no longer works.
If I use p.getsettings("Android_Id") (or any other string)
I get an entirely different number.

Any help would be greatly appreciated

Terry
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
GetDeviceID

I have the same problem. This no longer functions. Is there a replacement function within the Phone library or other?
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
The new method (for those who will not / can not read the documentation :sign0161:) is
B4X:
Dim p As PhoneId
    Dim id As String
    id = p.GetDeviceId
 
Upvote 0

TDowdeswell

Member
Licensed User
Longtime User
GetDeviceid

I found the release notice immediately after posting - my apologies.

Interesting that it returns a different number to before the upgrade, however (previously it ws all zeros, now it has same leading numerics)?
 
Upvote 0

corsaro

Member
Licensed User
Longtime User
The method hasn't changed. It only moved.

Using the code inside test2.zip, I have changed Phone to PhoneId,
but I receive this error during debug:

java.lang.Number.FormatException

on this line: password=Bit.ToOctalString(Floor((codid/150)+4528657583465))

I use lib Phone version 1.91
 
Upvote 0
Top