Getting IP Address, deviceID or phone number?

Monkey Targets Forums/Android/Getting IP Address, deviceID or phone number?

Xyle(Posted 2014) [#1]
Been mashing about with these issues for a bit.

I would love to get all of these to help identify a user that accesses the scoreboard in order to keep the information intact and stop double posts, etc.

The problem is trying to implement the Telephony manager seems like quite the overkill for my little bitty game.

I was looking to see if there were any simpler solutions to getting any of these identifiers.

Another option was to produce a unique ID, but I can see quite a bit of problems with implementing a system like that also.

Thanks for any input or help!


Xyle(Posted 2014) [#2]
Well after reading through a ton of info it seems using an app created unique ID is the way to go.
There is some pretty good info about this here...

http://android-developers.blogspot.com/2011/03/identifying-app-installations.html


Xyle(Posted 2014) [#3]
After a bit, I finally got the unique ID figured out...

Create a java file called Installation.java, I stored it in the my main monkey game folder
import android.content.Context

class Installation {
    private static String sID = null;
    private static final String INSTALLATION = "INSTALLATION";
    
	public synchronized static String id() {
                //Getting the context was the tough part, but thanks to the search function, I was able to plug it together!
		Context context = BBAndroidGame._androidGame._activity.getApplicationContext();
		
        if (sID == null) {  
            File installation = new File(context.getFilesDir(), INSTALLATION);
            try {
                if (!installation.exists())
                    writeInstallationFile(installation);
                sID = readInstallationFile(installation);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return sID;
    }

    private static String readInstallationFile(File installation) throws IOException {
        RandomAccessFile f = new RandomAccessFile(installation, "r");
        byte[] bytes = new byte[(int) f.length()];
        f.readFully(bytes);
        f.close();
        return new String(bytes);
    }

    private static void writeInstallationFile(File installation) throws IOException {
        FileOutputStream out = new FileOutputStream(installation);
        String id = UUID.randomUUID().toString();
        out.write(id.getBytes());
        out.close();
    }
}


Then in the main monkey game solution from Jungle IDE...
Strict 

Import mojo
Import "Installation.java"

Extern
	#If TARGET="android"	
		Function CheckInstall:String() = "Installation.id"
	#Endif
Public

Class Game Extends App
        Field pID:String
	Method OnCreate:Int()
		pID = CheckInstall()
		Print("pID: " + pID)
		Return(0)
	End Method

       'Rest of the code goes here
End


This will create a unique id when the application is first installed and loaded. When its reloaded, the print shows the same ID number. The problem with this though, if the user uninstalls the app and reinstalls it, they will get a new unique ID.


ziggy(Posted 2014) [#4]
I did found this can be useful to you too:
http://www.anddev.org/tinytut_-_getting_the_imsi_-_imei_sim-device_unique_ids-t446.html


Xyle(Posted 2014) [#5]
Thanks for the input!

After reading through a slew of information on getting and using these kinds of identifiers and the problems that can arise from attempting to get them, I decided to stay away from it and just use a program generated ID code.

Basically, it looks to me, you would have more code to make telephony or similar modules work than the game itself, lol!

Thanks again!


ziggy(Posted 2014) [#6]
Maybe you could use a GUID. Not sure if there's any Monkey module for it