2

I am new in Android. I am developing a simple application where I need to send push notification from server side.

So, need to send data using call api when app install. For that, I have to get device information like device name, version, unique key (token) etc.

I tried but not get how to? any one have a idea please share with me.

Kara
  • 6,115
  • 16
  • 50
  • 57
user1780370
  • 851
  • 1
  • 17
  • 27

6 Answers6

5

Hi please see below method hope you will get most of detail which you want

public static String getDeviceInfo(String p_seperator) throws Throwable
{
    String m_data = "";
    StringBuilder m_builder = new StringBuilder();
    m_builder.append("RELEASE " + android.os.Build.VERSION.RELEASE + p_seperator);
    m_builder.append("DEVICE " + android.os.Build.DEVICE + p_seperator);
    m_builder.append("MODEL " + android.os.Build.MODEL + p_seperator);
    m_builder.append("PRODUCT " + android.os.Build.PRODUCT + p_seperator);
    m_builder.append("BRAND " + android.os.Build.BRAND + p_seperator);
    m_builder.append("DISPLAY " + android.os.Build.DISPLAY + p_seperator);
    // TODO : android.os.Build.CPU_ABI is deprecated
    m_builder.append("CPU_ABI " + android.os.Build.CPU_ABI + p_seperator);
    // TODO : android.os.Build.CPU_ABI2 is deprecated
    m_builder.append("CPU_ABI2 " + android.os.Build.CPU_ABI2 + p_seperator);
    m_builder.append("UNKNOWN " + android.os.Build.UNKNOWN + p_seperator);
    m_builder.append("HARDWARE " + android.os.Build.HARDWARE + p_seperator);
    m_builder.append("ID " + android.os.Build.ID + p_seperator);
    m_builder.append("MANUFACTURER " + android.os.Build.MANUFACTURER + p_seperator);
    m_builder.append("SERIAL " + android.os.Build.SERIAL + p_seperator);
    m_builder.append("USER " + android.os.Build.USER + p_seperator);
    m_builder.append("HOST " + android.os.Build.HOST + p_seperator);
    m_data = m_builder.toString();
    return m_data;
}

below method is for getting device ID

public static String getDeviceID(Context p_context) throws Throwable
{
    String m_deviceID = null;
    TelephonyManager m_telephonyManager = null;
    m_telephonyManager = (TelephonyManager) p_context
            .getSystemService(Context.TELEPHONY_SERVICE);

    m_deviceID = m_telephonyManager.getDeviceId().toString();

    if (m_deviceID == null || "00000000000000".equalsIgnoreCase(m_deviceID))
    {
        m_deviceID = "AAAAAAA";
    }

    return m_deviceID;
}
Jas
  • 3,207
  • 2
  • 15
  • 45
2

Use these lines of code .. it will return you android_device_id , and name. You can get many other thing by replacing the last KeyWord ANDROID_ID ....

String android_id = Settings.Secure.getString(getApplicationContext().getContentResolver(),
                Settings.Secure.ANDROID_ID);

        String android_name= Settings.Secure.getString(getApplicationContext().getContentResolver(),
                Settings.Secure.NAME);
Himanshu Shekher Jha
  • 1,334
  • 2
  • 14
  • 27
1

Token

import android.provider.Settings.Secure;

private String android_id = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID); 

or

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

Android version

android.os.Build.VERSION

Device name

android.os.Build.MODEL;
Community
  • 1
  • 1
user2413972
  • 1,355
  • 2
  • 9
  • 25
0
Log.i("ManuFacturer :", Build.MANUFACTURER);
Log.i("Board : ", Build.BOARD);
Log.i("Display : ", Build.DISPLAY);

For More information Please visit: http://developer.android.com/reference/android/os/Build.html

Regarding Push Notifications, you should follow these steps.

  1. Create/Register App on Google Cloud
  2. Setup Cloud SDK with Development
  3. Configure project for GCM
  4. Get Device Registration ID
  5. Send Push Notifications
  6. Receive Push Notifications

For detail of each step please visit here : http://rdcworld-android.blogspot.in/2013/11/android-push-notification-google-cloud.html

Akber
  • 521
  • 4
  • 10
  • What use for send push notification? how to get register id? – user1780370 Sep 17 '15 at 05:52
  • you can use **Build.ID**, here you go and follow its step http://rdcworld-android.blogspot.in/2013/11/android-push-notification-google-cloud.html – Akber Sep 17 '15 at 05:55
0

Try this links:

http://developer.android.com/reference/android/os/Build.html and http://developer.android.com/reference/java/lang/System.html (try getProperty() )

For Example :

System.getProperty("os.version"); // OS version
android.os.Build.VERSION.SDK      // API Level
android.os.Build.DEVICE           // Device
android.os.Build.MODEL            // Model 
android.os.Build.PRODUCT          // Product

Etc...

Burhanuddin Rashid
  • 5,260
  • 6
  • 34
  • 51
0

The answers here are all unrelated to the OP question.

To get register id for push notifications.

GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
String regid = gcm.register("YOUR_PROJECT_ID");

You can get your project id from https://console.developers.google.com/project

You should read more detailed information at https://developers.google.com/cloud-messaging/gcm

Gunhan
  • 6,807
  • 3
  • 43
  • 37