Android Utililty Methods Context Set

List of utility methods to do Context Set

Description

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

Method

voidscanMediaFiles(final Context context, String[] files, String[] mimeTypes)
scan Media Files
MediaScannerConnection.scanFile(context, files, mimeTypes,
        new OnScanCompletedListener() {
            @Override
            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
sendKey(c, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
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) {
    paramContext.getPackageManager().setComponentEnabledSetting(
            new ComponentName(paramContext.getPackageName(),
                    "com.baidu.location.f"), i, 1);
    return;
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);
Locale.setDefault(locJa);
Configuration config = new Configuration();
config.locale = locJa;
if (context != null) {
    context.getResources().updateConfiguration(config,
            context.getResources().getDisplayMetrics());