Back to project page Android-SDK.
The source code is released under:
MIT License
If you think the Android project Android-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.getcloudengine; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.util.Log; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; /*from w w w. jav a 2s . c o m*/ /** * This class needs to be instantiated and initialized by every app at the beginning * of its execution, typically in the onCreate method of its main activity. */ public class CloudEngine { private static final String TAG = "CloudEngine"; private static String apiKey = null; private static String appId = null; private static Context app_context = null; public static final String APP_ID = "AppId"; public static final String API_KEY = "AppKey"; public static final String PREFERENCE_FILE = "net.getcloudengine.PREFERENCE_FILE_KEY"; static String applicationName; /** * Initialize the Cloudengine library functions and services. * * @param ctx * The application context object * * @param key The REST API client key given to the user * * @param appid The application id for current application * */ public static void initialize(Context ctx, String key, String app_id) { if(ctx == null || key == null || app_id == null || key == "" || app_id == ""){ throw new CloudException("Invalid arguments provided"); } apiKey = key; appId = app_id; app_context = ctx; applicationName = ctx.getResources().getString(R.string.app_name); initPushService(); saveCredentials(); CookieSyncManager syncManager = CookieSyncManager.createInstance(ctx); syncManager.sync(); } static String getApiKey(){ return apiKey; } static String getAppId(){ return appId; } private static void saveCredentials(){ SharedPreferences sharedPref = app_context.getSharedPreferences( PREFERENCE_FILE , Context.MODE_PRIVATE); String key = sharedPref.getString(API_KEY, null); String id = sharedPref.getString(APP_ID, null); if(key == null || id == null) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putString(API_KEY, apiKey); editor.putString(APP_ID, appId); editor.commit(); } } private static void initPushService() { CloudEngineUtils utils = CloudEngineUtils.getInstance(); if(!utils.isNetworkAvailable(app_context)) { return; } //Check if push service is running Log.d(TAG, "CloudEngine starting Push service"); //Start Push notification service Intent intent = new Intent(app_context, CloudPushService.class); app_context.startService(intent); return; } static Context getContext() { return app_context; } }