Android Utililty Methods Context Set

List of utility methods to do Context Set


The list of methods to do Context Set are organized into topic(s).


voidscanMediaFiles(final Context context, String[] files, String[] mimeTypes)
scan Media Files
MediaScannerConnection.scanFile(context, files, mimeTypes,
        new OnScanCompletedListener() {
            public void onScanCompleted(String arg0, Uri arg1) {
voidsendKey(Context c, int action, int keycode)
Create and send a KeyEvent through the AudioService, failback to a simple intent broadcast if necessary.On KitKat, the event should be send by the service, otherwise it's not working with SELinux enforced mode.
long eventtime = SystemClock.uptimeMillis();
KeyEvent keyEvent = new KeyEvent(eventtime, eventtime, action,
        keycode, 0);
if (!sendMediaKeyEventViaAudioService(keyEvent)) {
    Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
    downIntent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent);
    c.sendOrderedBroadcast(downIntent, null);
voidsendKey(Context c, int keyCode)
Send two KeyEvent, one with Action_down and then one with Action_up
sendKey(c, KeyEvent.ACTION_DOWN, keyCode);
sendKey(c, KeyEvent.ACTION_UP, keyCode);
voidsendPlayPauseKey(Context c)
send Play Pause Key
booleansendSms(@Nonnull Context context, @CheckForNull String number, @Nullable String text)
Sends an SMS message to the given number with the passed text.
boolean success = true;
if (hasTelephony(context)) {
    if (number == null
            || !PhoneNumberUtils.isWellFormedSmsAddress(number)) {
        number = ""; 
        success = false;
    Intent smsIntent = new Intent(Intent.ACTION_SENDTO,
voidsendStopKey(Context c)
send Stop Key
sendKey(c, KeyEvent.KEYCODE_MEDIA_STOP);
voidsetAppContext(Context context)
set App Context
sContext = context;
voidsetBaiduServiceEnabled(Context paramContext, boolean paramBoolean)
set Baidu Service Enabled
if (paramBoolean)
for (int i = 1;; i = 2) {
            new ComponentName(paramContext.getPackageName(),
                    ""), i, 1);
voidsetContext(Application app)
set Context
context = app.getApplicationContext();
voidsetDefaultLocale(Context context, String locale)
Change the default locale of the application for this activity
Locale locJa = new Locale(locale);
Configuration config = new Configuration();
config.locale = locJa;
if (context != null) {