Code example for GoogleCloudMessaging

Methods: send

0
            PackageInfo packageInfo = context.getPackageManager()
                    .getPackageInfo(context.getPackageName(), 0);
            return packageInfo.versionCode;
        } catch (NameNotFoundException e) {
            // should never happen 
            throw new RuntimeException("Could not get package name: " + e);
        } 
    } 
 
    /** 
     * @return Application's {@code SharedPreferences}. 
     */ 
    private SharedPreferences getGCMPreferences(Context context) {
        return getSharedPreferences(DemoActivity.class.getSimpleName(), Context.MODE_PRIVATE);
    } 
 
    /** 
     * Checks if the registration has expired. 
     * 
     * <p>To avoid the scenario where the device sends the registration to the 
     * server but the server loses it, the app developer may choose to re-register