List of usage examples for android.content Context getApplicationContext
public abstract Context getApplicationContext();
From source file:org.cvasilak.jboss.mobile.app.net.TalkToJBossServerTask.java
public TalkToJBossServerTask(Context context, Server server, Callback callback, boolean shouldProcessRequest) { this.context = context; this.server = server; this.callback = callback; this.shouldProcessRequest = shouldProcessRequest; this.client = CustomHTTPClient.getHttpClient(); this.jsonBuilder = ((JBossAdminApplication) context.getApplicationContext()).getJSONBuilder(); this.jsonParser = ((JBossAdminApplication) context.getApplicationContext()).getJSONParser(); Credentials credentials = new UsernamePasswordCredentials(server.getUsername(), server.getPassword()); client.getCredentialsProvider().setCredentials( new AuthScope(server.getHostname(), server.getPort(), AuthScope.ANY_REALM), credentials); }
From source file:com.hybris.mobile.lib.http.manager.volley.VolleyPersistenceManager.java
public VolleyPersistenceManager(Context applicationContext) { this(applicationContext.getApplicationContext(), null, null); }
From source file:fr.cobaltians.cobalt.Cobalt.java
/********************************************************************************************** * CONSTRUCTORS// ww w.j a v a2 s . c o m **********************************************************************************************/ private Cobalt(Context context) { mContext = context.getApplicationContext(); }
From source file:com.openerp.orm.OEHelper.java
public OEHelper(Context context) { init();//from w w w.j a v a 2 s.c o m mContext = context; mApp = (App) context.getApplicationContext(); mOpenERP = mApp.getOEInstance(); mUser = OEUser.current(context); if (mUser != null) { mUser = login(mUser.getUsername(), mUser.getPassword(), mUser.getDatabase(), mUser.getHost()); } }
From source file:com.iiitd.networking.UDPMessenger.java
/** * Class constructor// w w w .jav a2 s . c o m * @param context the application's context * @param tag a valid string, used to filter the UDP broadcast messages (in and out). It can't be null or 0-characters long. * @param multicastPort the port to multicast to. Must be between 1025 and 49151 (inclusive) * @param connectionPort the port to get the connection back. Must be between 1025 and 49151 */ public UDPMessenger(Context context, String tag, int multicastPort) throws IllegalArgumentException { if (context == null || tag == null || tag.length() == 0 || multicastPort <= 1024 || multicastPort > 49151) throw new IllegalArgumentException(); this.context = context.getApplicationContext(); TAG = tag; MULTICAST_PORT = multicastPort; incomingMessageHandler = new Handler(Looper.getMainLooper()); }
From source file:fr.bmartel.android.tictactoe.GameSingleton.java
private GameSingleton(Context context) { this.context = context.getApplicationContext(); this.executor = Executors.newFixedThreadPool(1); //queue = Volley.newRequestQueue(context.getApplicationContext()); HttpStack hurlStack = new HurlStack() { @Override//from w ww.ja va 2 s.co m protected HttpURLConnection createConnection(URL url) throws IOException { HttpsURLConnection httpsURLConnection = (HttpsURLConnection) super.createConnection(url); try { httpsURLConnection.setSSLSocketFactory(SSLCertificateSocketFactory.getInsecure(0, null)); httpsURLConnection.setHostnameVerifier(new AllowAllHostnameVerifier()); } catch (Exception e) { e.printStackTrace(); } return httpsURLConnection; } }; queue = Volley.newRequestQueue(context, hurlStack); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); //load device id from shared preference DEVICE_ID = sharedPreferences.getString(RequestConstants.DEVICE_ID, ""); deviceName = sharedPreferences.getString(RequestConstants.DEVICE_NAME, RequestConstants.DEFAULT_USERNAME); if (DEVICE_ID.equals("")) { //register deviceId in shared preference SharedPreferences.Editor editor = sharedPreferences.edit(); DEVICE_ID = new RandomGen(DEVICE_ID_SIZE).nextString(); editor.putString(RequestConstants.DEVICE_ID, DEVICE_ID); editor.commit(); } JsonObjectRequest jsObjRequest = new JsonObjectRequest(BuildConfig.APP_ROUTE + "/connect", RequestBuilder.buildConnectionRequest(DEVICE_ID, deviceName), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.i(TAG, "response received connect : " + response.toString()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub error.printStackTrace(); } }); jsObjRequest.setShouldCache(false); queue.add(jsObjRequest); Log.i(TAG, "device id " + DEVICE_ID + " initialized"); if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(context, RegistrationIntentService.class); context.startService(intent); } }
From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java
public void open(Context context) throws SQLException { String password = ((CustomApplication) context.getApplicationContext()).getPassword(); mDatabase = mDbHelper.openDatabase(password); }
From source file:com.openerp.orm.OEHelper.java
public OEHelper(Context context, boolean withUser) { init();//from ww w. j ava 2 s . c o m mContext = context; mApp = (App) context.getApplicationContext(); mOpenERP = mApp.getOEInstance(); this.withUser = withUser; }
From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.ChannelService.java
public static void createChannel(Context ctx) { String regId = getGCMRegId(ctx); if (regId.isEmpty()) { log.warn("regId is empty. It will get from GCM register"); return;//from w w w.j a v a 2 s .c o m } Account ac = AccountUtils.getAccount(ctx, false); AccountManager am = (AccountManager) ctx.getSystemService(Context.ACCOUNT_SERVICE); String userId; try { userId = am.getUserData(ac, JsonKeys.ID_STORED); } catch (Exception e) { log.error("Cannot get userId", e); return; } String json; try { json = registerInServer(ctx, regId, userId); } catch (Exception e) { log.error("Cannot send regId to server", e); return; } if (json == null) { log.error("Cannot get channelId"); return; } try { JSONObject obj = new JSONObject(json); String channelId = obj.getString(JsonKeys.CHANNEL_ID); storeRegistrationId(ctx, regId, channelId); Intent i = new Intent(ConstantKeys.BROADCAST_SERVER_REGISTER); ctx.sendBroadcast(i); } catch (JSONException e) { log.error("Error processing register result", e); } ctx.startService(new Intent(ctx.getApplicationContext(), CommandGetService.class)); }
From source file:org.pixmob.appengine.client.AppEngineClient.java
/** * Create a new instance. No account is set: the method * {@link #setAccount(String)} must be called prior to executing a request. * @param context used for getting services and starting intents * @param appEngineHost hostname where the AppEngine is hosted * @param delegate {@link HttpClient} instance for making HTTP requests *//*from w w w . ja v a 2 s . c o m*/ public AppEngineClient(final Context context, final String appEngineHost, final HttpClient delegate) { this.context = context.getApplicationContext(); this.appEngineHost = appEngineHost; delegateWasSet = delegate != null; this.delegate = delegateWasSet ? delegate : SSLEnabledHttpClient.newInstance(HTTP_USER_AGENT); accountManager = AccountManager.get(context); loginClient = SSLEnabledHttpClient.newInstance(HTTP_USER_AGENT); loginClient.setCookieStore(new BasicCookieStore()); loginClient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); setRetryCount(3); }