1

I am working on an android project,on that project i am stuck on "when client send data into a remote database server then he or she have to use an unique no" so i decided to use phone mac address so that i can avoid duplication of id no,For now i am use

public void minInteger(View view){
    minteger = minteger + 1;
    display(minteger);
}

public void display(int number){
    TextView displayInteger = (TextView)findViewById(R.id.randGe);
    displayInteger.setText("Integer: "+number);
}

This app will use by few client like 20-30 peoples.

nakano531
  • 498
  • 7
  • 13
user3728517
  • 157
  • 3
  • 10
  • This is how you get the mac address : http://stackoverflow.com/questions/33103798/how-to-get-wi-fi-mac-address-in-android-marshmallow/35830358#35830358 – Arsen Davtyan Nov 08 '16 at 03:26
  • A MAC address isn't a good choice for a unique ID - see this article for better options: https://developer.android.com/training/articles/user-data-ids.html – k2col Nov 08 '16 at 03:40

4 Answers4

0

Don't use the MAC address. First off, you may not have one- you only have one if you're on wifi (cellular doesn't use MACs). Secondly, Android has restricted the ability to get that on newer OSes. Use the Android id instead, or dynamically generate a UUID and use that.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

there are many ways you can produce a unique id for each client, if you just want totally unique number you can use nano time:

System.nanoTime()

but it you want to use kinda unique per device use uuid:

TelephonyManager tManager  = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uuid = tManager.getDeviceId();

Hope this help.

0

Thanks everybody as many of you suggest me to not use mac address as an unique id,i am also do some google and find that using mac address may not a good way to solve my problem so i implement this concept in different way.Going to close this thread thanks everyone for your response.

user3728517
  • 157
  • 3
  • 10
0

Hope this helps you

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String macAddress = wifiInfo.getMacAddress();

And add this permission in your manifest

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Kishan Soni
  • 816
  • 1
  • 6
  • 19