Android Context - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Context class.

This code example shows how to use the following methods:getContentResolver, getFilesDir, openFileOutput, sendBroadcast, sleep
                    "dfrsRsFMrFpk++mSt6SoxXaMbn0LL2u1CD4PCEiQMGt+lK3/3TmRTKNs+23sYS7Ahjxj0udDAkEA" + 
                    "p57Nj65WNaWeYiOfTwKXkLj8l29H5NbaGWxPT0XkWr4PvBOFZVH/wj0/qc3CMVGnv11+DyO+QUCN" + 
                    "SqBB5aRe8g=="; 
 
    private void overrideSettings(String key, String value) throws Exception {
        assertTrue(Settings.Secure.putString(mContext.getContentResolver(), key, value));
        Thread.sleep(1000);
    } 
 
    private void overrideCert(String value) throws Exception {
        overrideSettings(PINLIST_CERTIFICATE_KEY, value);
    } 
 
    private String readPins() throws Exception {
        return IoUtils.readFileAsString(PINLIST_CONTENT_PATH);
    } 
 
    private String readCurrentVersion() throws Exception {
        return IoUtils.readFileAsString("/data/misc/keychain/metadata/version"); 
    } 

9
CodeRank
This code example shows how to use the following methods:getBroadcast, getSystemService, getDefaultSharedPreferences
  @Override 
  public void onReceive(Context context, Intent intent) {
    Log.w("DirectoryUpdateReceiver", "Initiating scheduled directory update...");
 
    try { 
      SignalingSocket signalingSocket = new SignalingSocket(context);
      DirectoryResponse response      = signalingSocket.getNumberFilter();
 
      if (response != null) {
        NumberFilter filter = new NumberFilter(response.getFilter(), response.getHashCount());
        filter.serializeToFile(context);
      } 
    } catch (SignalingException se) {
      Log.w("DirectoryUpdateReceiver", se);
    } catch (Exception e) {
      Log.w("DirectoryUpdateReceiver", e);
      return; 
    } 
 
    scheduleDirectoryUpdate(context);

9
CodeRank
This code example shows how to use the following methods:getBroadcast, getSystemService
                ", error = " + error + ", removed = " + removed);
        } 
 
        if (removed != null) {
            // Remember we are unregistered 
            C2DMessaging.clearRegistrationId(context);
            onUnregistered(context);
            return; 
        } else if (error != null) {
            // we are not registered, can try again 
            C2DMessaging.clearRegistrationId(context);
            // Registration failed 
            Log.e(TAG, "Registration error " + error);
            onError(context, error);
            if ("SERVICE_NOT_AVAILABLE".equals(error)) {
                long backoffTimeMs = C2DMessaging.getBackoff(context);
                 
                Log.d(TAG, "Scheduling registration retry, backoff = " + backoffTimeMs);
                Intent retryIntent = new Intent(C2DM_RETRY);
                PendingIntent retryPIntent = PendingIntent.getBroadcast(context, 

8
CodeRank
This code example shows how to use the following methods:getBroadcast, getMainLooper, getSystemService
9
CodeRank
This code example shows how to use the following methods:getBroadcast, getSharedPreferences, getSystemService
     */ 
    public void onRegistered(Context context, String registrationId) throws IOException {
        // registrationId will also be saved 
    } 
 
    /** 
     * Called when the device has been unregistered. 
     */ 
    public void onUnregistered(Context context) {
    } 
 
     
    @Override 
    public final void onHandleIntent(Intent intent) {
        try { 
            Context context = getApplicationContext();
            if (intent.getAction().equals(REGISTRATION_CALLBACK_INTENT)) {
                handleRegistration(context, intent);
            } else if (intent.getAction().equals(C2DM_INTENT)) {
                onMessage(context, intent);

8
CodeRank
This code example shows how to use the following methods:obtainStyledAttributes
    assertThat(dataDir.exists()).isTrue();
  } 
 
  @Test 
  public void shouldStubThemeStuff() throws Exception { 
    assertThat(context.obtainStyledAttributes(null)).isNotNull();
    assertThat(context.obtainStyledAttributes(0, null)).isNotNull();
    assertThat(context.obtainStyledAttributes(null, null)).isNotNull();
    assertThat(context.obtainStyledAttributes(null, null, 0, 0)).isNotNull();
  } 
 
  @Test 
  public void getCacheDir_shouldCreateDirectory() throws Exception { 
    assertTrue(context.getCacheDir().exists());
  } 
 
  @Test 
  public void getExternalCacheDir_shouldCreateDirectory() throws Exception { 
    assertTrue(context.getExternalCacheDir().exists());
  } 
8
CodeRank
This code example shows how to use the following methods:getString, getPackageName, getResources
This code example shows how to use the following methods:startService, getDefaultSharedPreferences
import android.preference.PreferenceManager; 
 
public class NetworkReceiver extends BroadcastReceiver {
  @Override 
  public void onReceive(Context context, Intent intent) {
    SharedPreferences prefs=
        PreferenceManager.getDefaultSharedPreferences(context);
 
    if (SyncService.isSyncNeeded(context, prefs)) {
      context.startService(new Intent(context, SyncService.class));
    } 
  } 
} 
8
CodeRank
This code example shows how to use the following methods:getClassLoader, getDir, getPackageManager, getPackageName
8
CodeRank
This code example shows how to use the following methods:registerReceiver, addAction
    protected void onAttachedToWindow() { 
        super.onAttachedToWindow(); 
 
        if (!mAttached) {
            mAttached = true;
            IntentFilter filter = new IntentFilter();
 
            filter.addAction(Intent.ACTION_TIME_TICK);
            filter.addAction(Intent.ACTION_TIME_CHANGED);
            filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
            filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
 
            getContext().registerReceiver(mIntentReceiver, filter, null, getHandler());
        } 
 
        // NOTE: It's safe to do these after registering the receiver since the receiver always runs 
        // in the main thread, therefore the receiver can't run before this method returns. 
 
        // The time zone may have changed while the receiver wasn't registered, so update the Time 
        mCalendar = Calendar.getInstance(TimeZone.getDefault());
8
CodeRank

Related Android Context Questions & Answers:

Other Android Context Examples

12:	
13:	  @Override
14:	  public void onUpdate(Context context, AppWidgetManager appWidgetManager,
15:	      int[] appWidgetIds) {
16:

Read More

6:	public class ConnectionDetector {
7:		
8:		private Context _context;
9:		
10:		public ConnectionDetector(Context context){
-
8:		private Context _context;
9:		
10:		public ConnectionDetector(Context context){
11:			this._context = context;
12:		}

Read More

6:	public class ConnectionDetector {
7:	 
8:	    private Context _context;
9:	 
10:	    public ConnectionDetector(Context context){
-
8:	    private Context _context;
9:	 
10:	    public ConnectionDetector(Context context){
11:	        this._context = context;
12:	    }

Read More

6:	public class ConnectionDetector {
7:	 
8:	    private Context _context;
9:	 
10:	    public ConnectionDetector(Context context){
-
8:	    private Context _context;
9:	 
10:	    public ConnectionDetector(Context context){
11:	        this._context = context;
12:	    }

Read More

2:	
3:	    @Override
4:	    public void onDisabled(Context context, Intent intent) {
5:	        // Called when the app is about to be deactivated as a device administrator.
6:	        // Deletes previously stored password policy.

Read More

1:	public class ImageAdapter extends BaseAdapter {
2:	    private Context mContext;
3:	
4:	    public ImageAdapter(Context c) {
-
2:	    private Context mContext;
3:	
4:	    public ImageAdapter(Context c) {
5:	        mContext = c;
6:	    }

Read More

See Code Examples for Android Context Methods: