Mega Code Archive

 
Categories / Android / Core Class
 

Returns the DeviceId according to the TelephonyManager

//package org.acra.util; import java.io.File; import android.content.Context; import android.content.res.Configuration; import android.os.Environment; import android.os.StatFs; import android.telephony.TelephonyManager; import android.util.DisplayMetrics; import android.util.Log; import android.view.Display; import android.view.WindowManager; /**  * Responsible for providing base utilities used when constructing the report.  * <p/>  * @author William Ferguson  * @since 4.3.0  */ public final class ReportUtils {     /**      * Returns the DeviceId according to the TelephonyManager.      *      * @param context   Context for the application being reported.      * @return Returns the DeviceId according to the TelephonyManager or null if there is no TelephonyManager.      */     public static String getDeviceId(Context context) {         try {             final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);             return tm.getDeviceId();         } catch (RuntimeException e) {           //  Log.w(ACRA.LOG_TAG, "Couldn't retrieve DeviceId for : " + context.getPackageName(), e);             return null;         }     } }