Best code examples for Android Context class (android.content.Context)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Context class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android Context examples from Open Source projects
This code example shows how to use the following methods: getContentResolver, getFilesDir, openFileOutput, sendBroadcast, sleep
103:	assertTrue(Settings.Secure.putString(mContext.getContentResolver(), key, value)); 
104:	Thread.sleep(1000); 
-
154:	FileOutputStream fw = mContext.openFileOutput("content.txt", mContext.MODE_WORLD_READABLE); 
-
157:	return mContext.getFilesDir() + "/content.txt"; 
-
190:	mContext.sendBroadcast(i); 
-
199:	Thread.sleep(1000); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getBroadcast, getSystemService, getDefaultSharedPreferences
50:	SignalingSocket signalingSocket = new SignalingSocket(context); 
-
55:	filter.serializeToFile(context); 
-
68:	SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); 
69:	AlarmManager am               = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); 
-
71:	PendingIntent sender          = PendingIntent.getBroadcast(context, 0, intent, 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getBroadcast, getSystemService
161:	C2DMessaging.clearRegistrationId(context); 
-
166:	C2DMessaging.clearRegistrationId(context); 
-
169:	onError(context, error); 
-
171:	long backoffTimeMs = C2DMessaging.getBackoff(context); 
-
175:	PendingIntent retryPIntent = PendingIntent.getBroadcast(context, 
-
178:	AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
-
184:	C2DMessaging.setBackoff(context, backoffTimeMs); 
-
189:	C2DMessaging.setRegistrationId(context, registrationId); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getBroadcast, getMainLooper, getSystemService
106:	mAlarmService = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
-
108:	PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); 
-
111:	mHandler = new Handler(mContext.getMainLooper()); 
-
115:	mUpdateIdleMaintenanceStatePendingIntent = PendingIntent.getBroadcast(mContext, 0, 
-
118:	register(mContext.getMainLooper()); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: getBroadcast, getSharedPreferences, getSystemService
93:	/** 
-
169:	onError(context, error); 
-
175:	PendingIntent retryPIntent = PendingIntent.getBroadcast(context, 
-
178:	AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: obtainStyledAttributes
97:	assertThat(context.obtainStyledAttributes(null)).isNotNull(); 
98:	assertThat(context.obtainStyledAttributes(0, null)).isNotNull(); 
99:	assertThat(context.obtainStyledAttributes(null, null)).isNotNull(); 
100:	assertThat(context.obtainStyledAttributes(null, null, 0, 0)).isNotNull(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getString, getPackageName, getResources
83:	progressDialogTitleId = activity.getResources().getIdentifier( 
84:	PROGRESS_DIALOG_TITLE_RESOURCE, "string", activity.getPackageName()); 
-
88:	progressDialogMsgId = activity.getResources().getIdentifier( 
89:	PROGRESS_DIALOG_MESSAGE_RESOURCE, "string", activity.getPackageName()); 
-
91:	progressDialog.setMessage(activity.getString(progressDialogMsgId)); 
-
93:	progressDialog.setOnKeyListener(new OnKeyListener() { 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: startService, getDefaultSharedPreferences
26:	SharedPreferences prefs= 
-
29:	if (SyncService.isSyncNeeded(context, prefs)) { 
30:	context.startService(new Intent(context, SyncService.class)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getClassLoader, getDir, getPackageManager, getPackageName
19:	defaultClassLoader = androidContext.getClassLoader(); 
20:	PackageManager pkgMgr = androidContext.getPackageManager(); 
-
23:	&& pkgMgr.checkSignatures(androidContext.getPackageName(), packageName) >= 0) { 
-
29:	String dexOutputDir = androidContext.getDir("dex", 0).getAbsolutePath(); 
-
31:	androidContext.getClassLoader()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: registerReceiver, addAction
80:	IntentFilter filter = new IntentFilter(); 
-
82:	filter.addAction(Intent.ACTION_TIME_TICK); 
83:	filter.addAction(Intent.ACTION_TIME_CHANGED); 
84:	filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); 
85:	filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); 
-
87:	getContext().registerReceiver(mIntentReceiver, filter, null, getHandler()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getSystemService
117:	mNotificationManager = (NotificationManager) context.getSystemService(ns); 
-
119:	Notification noti = StatusNotificationIntent.buildNotification(context, tag, contentTitle, contentText, flag); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getResources
71:	if(context == null || context.getResources() == null) 
-
74:	ContextManager.setContext(context); 
-
79:	getSyncProvider().synchronize(context); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getContentResolver, getPackageManager, getPackageName
57:	String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); 
-
60:	androidId = android.provider.Settings.System.getString(context.getContentResolver(), 
-
86:	PackageManager pm = context.getPackageManager(); 
87:	PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getContentResolver, getSystemService
137:	AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); 
138:	Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); 
-
144:	boolean vibrateWhenRinging = Settings.System.getInt(context.getContentResolver(), "vibrate_when_ringing", 0) != 0; 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getSystemService, startActivity
251:	mContext.startActivity(intent); 
-
274:	mKeyguardManager = (KeyguardManager)mContext.getSystemService(Context.KEYGUARD_SERVICE); 
-
287:	PhoneWindowManager.sendCloseSystemWindows(mContext, null); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getResources
38:	return makeText(context, context.getResources().getString(resId), duration); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getResources
30:	super(context); 
-
33:	metrics = context.getResources().getDisplayMetrics(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getApplicationContext, getResources, getSharedPreferences
52:	return context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); 
-
58:	} 
-
73:	if ((context.getResources().getConfiguration().uiMode & 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getApplicationInfo, getPackageName, getResources, getSystemService
223:	String token = GoogleAuthUtil.getTokenWithNotification(ctx, GetAccountName(ctx), GetOauth2Scope(), new Bundle()); 
224:	GDocsHelper.SaveAuthToken(ctx, token); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: startActivity, getString
194:	downloadDialog.setPositiveButton(stringButtonYes, new DialogInterface.OnClickListener() { 
-
249:	activity.getString(stringTitle), 
250:	activity.getString(stringMessage), 
251:	activity.getString(stringButtonYes), 
252:	activity.getString(stringButtonNo)); 
-
279:	activity.startActivity(intent); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getService, getSystemService
45:	AlarmManager alarm = (AlarmManager) context.getSystemService( 
-
48:	PendingIntent sender = PendingIntent.getService(context, REQUEST_CODE, intent, PendingIntent.FLAG_CANCEL_CURRENT); 
-
52:	.getSystemService(Context.NOTIFICATION_SERVICE); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getResources, getSystemService
40:	inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
41:	loader = ImageLoader.getLoader(context); 
-
43:	displayMetrics = context.getResources().getDisplayMetrics(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: openFileOutput, getDefaultSharedPreferences
101:	fs = context.openFileOutput(normalized, Context.MODE_APPEND); 
-
103:	fs = context.openFileOutput(normalized, Context.MODE_PRIVATE); 
-
169:	return PreferenceManager.getDefaultSharedPreferences(this.context) 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getPackageManager, getPackageName
73:	return pContext.getPackageName(); 
-
77:	final PackageManager packMgmr = pContext.getPackageManager(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getContentResolver, sleep
46:	Settings.Secure.putString(mContext.getContentResolver(), key, value); 
47:	Thread.sleep(1000); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getBroadcast, getSharedPreferences, getSystemService
60:	SharedPreferences prefs=ctxt.getSharedPreferences(NAME, 0); 
-
68:	(AlarmManager)ctxt.getSystemService(Context.ALARM_SERVICE); 
-
70:	PendingIntent pi=PendingIntent.getBroadcast(ctxt, 0, i, 0); 
-
72:	listener.scheduleAlarms(mgr, pi, ctxt); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: registerReceiver, addAction
100:	IntentFilter filter = new IntentFilter(); 
101:	filter.addAction(TA_ANDROID_NET_CHANGE_ACTION); 
102:	filter.addAction(ANDROID_NET_CHANGE_ACTION); 
-
104:	.registerReceiver(getReceiver(), filter); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getSystemService
51:	super.__constructor__(context, c); 
-
53:	mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: startService
32:	ContextManager.setContext(context); 
-
37:	context.startService(new Intent(context, ReminderSchedulingService.class)); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getContentResolver, getPackageManager, getPackageName
108:	String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); 
-
111:	androidId = android.provider.Settings.System.getString(context.getContentResolver(), 
-
137:	PackageManager pm = context.getPackageManager(); 
138:	PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: registerReceiver, addAction
99:	IntentFilter filter = new IntentFilter(); 
-
101:	filter.addAction(Intent.ACTION_TIME_TICK); 
102:	filter.addAction(Intent.ACTION_TIME_CHANGED); 
103:	filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); 
104:	filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); 
-
106:	getContext().registerReceiver(mIntentReceiver, filter, null, getHandler()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getContentResolver, getPackageName
57:	final String installationId = Installation.id(context); 
58:	final String deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); 
59:	final String password = installationId + deviceId + context.getPackageName(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getActivity, getSystemService
23:	.getSystemService(context.NOTIFICATION_SERVICE); 
-
29:	PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: startService, getDefaultSharedPreferences
26:	SharedPreferences prefs= 
-
29:	if (SyncService.isSyncNeeded(context, prefs)) { 
30:	context.startService(new Intent(context, SyncService.class)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getString
117:	return newYesNoDialog(context, context.getString(titleId), context.getString(messageId), 
118:	context.getString(android.R.string.yes), context.getString(android.R.string.no), 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getResources
57:	super(context, attrs); 
-
59:	final float density = context.getResources().getDisplayMetrics().density; 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getResources
77:	final float scale = context.getResources().getDisplayMetrics().density; 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getActivity, getSystemService
24:	.getSystemService(context.NOTIFICATION_SERVICE); 
-
30:	PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: checkCallingOrSelfPermission, getCacheDir
55:	appCacheDir = context.getCacheDir(); 
-
119:	int perm = context.checkCallingOrSelfPermission(EXTERNAL_STORAGE_PERMISSION); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getContentResolver, startService
37:	ContentResolver res = context.getContentResolver(); 
-
40:	context.startService(loadavg); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getApplicationContext, getSharedPreferences
111:	Context applicationContext = context.getApplicationContext(); 
-
114:	this.cache = context.getSharedPreferences( 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getPackageName, getSystemService
34:	ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); 
-
38:	if (!topActivity.getPackageName().equals(context.getPackageName())) { 
Full Snippet Info
7
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: