Code example for Context

Methods: getContentResolvergetPackageManagergetPackageName

0
     *            the context 
     * @return the device's ANDROID_ID, or null if it could not be determined 
     * @see Secure#ANDROID_ID 
     */ 
    public static String getAndroidId(Context context) {
        String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        if (androidId == null) {
            // this happens on 1.6 and older 
            androidId = android.provider.Settings.System.getString(context.getContentResolver(),
                    android.provider.Settings.System.ANDROID_ID);
        } 
        return androidId;
    } 
 
    /** 
     * Same as {@link #getAndroidId(Context)}, but never returns null. 
     *  
     * @param context 
     *            the context 
     * @param fallbackValue 
     *            the fallback value 
     * @return the device's ANDROID_ID, or the fallback value if it could not be determined 
     * @see Secure#ANDROID_ID 
     */ 
    public static String getAndroidId(Context context, String fallbackValue) {
        String androidId = getAndroidId(context);
        if (androidId == null) {
            androidId = fallbackValue;
        } 
        return androidId;
    } 
 
    public static String getApplicationVersionString(Context context) {
        try { 
            PackageManager pm = context.getPackageManager();
            PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
            return "v" + info.versionName;
        } catch (Exception e) {
            e.printStackTrace();
            return null; 
        }