Example usage for android.app Activity getApplicationContext

List of usage examples for android.app Activity getApplicationContext

Introduction

In this page you can find the example usage for android.app Activity getApplicationContext.

Prototype

@Override
    public Context getApplicationContext() 

Source Link

Usage

From source file:Main.java

public static void skip(Activity aty, Class clazz, int requestCode) {
    if (aty == null || clazz == null)
        return;//from   w  w  w.java2  s .  co  m
    aty.startActivityForResult(new Intent(aty.getApplicationContext(), clazz), requestCode);
}

From source file:disono.webmons.com.utilities.helpers.WBFile.java

/**
 * Bitmap to file//  w w w . j a  va  2 s . c o  m
 *
 * @param activity
 * @param bitmap
 * @return
 */
public static File bmpToFile(Activity activity, Bitmap bitmap) {
    // CALL THIS METHOD TO GET THE URI FROM THE BITMAP
    Uri tempUri = WBFile.getBmpUri(activity.getApplicationContext(), bitmap);

    // CALL THIS METHOD TO GET THE ACTUAL PATH
    return new File(WBFile.getRealPathFromURI(activity, tempUri));
}

From source file:Main.java

public static void showToast(final Activity activity, final String message) {
    activity.runOnUiThread(new Runnable() {
        @Override/*from w w w .j  av a2  s  .  c o m*/
        public void run() {
            Toast toast = Toast.makeText(activity.getApplicationContext(), message, Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.BOTTOM, 0, 80);
            toast.show();
        }
    });
}

From source file:com.villetainio.travelcardreminder.activities.MainActivity.java

public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), ReadCardActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent,
            0);//  w  w w  . java  2  s .c o  m

    IntentFilter[] filters = new IntentFilter[1];
    String[][] techList = new String[][] {};

    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType("*/*"); //TODO Use only needed MIME based dispatches.
    } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("MIME type not supported.");
    }

    adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList);
}

From source file:Main.java

/**
 * Call it in onCreate for of activities where you using VK SDK
 * @param activity Your activity//ww w .  j a  v a2  s .  c om
 */
public static void onCreate(Activity activity) {
    if (sTopActivity != activity)
        sTopActivity = activity;
    if (sApplicationContext == null && activity != null) {
        sApplicationContext = activity.getApplicationContext();
    }
}

From source file:Main.java

/**
 * Call it in onResume for of activities where you using VK SDK
 * @param activity Your activity// www.  jav  a  2 s  .  co  m
 */
public static void onResume(Activity activity) {
    if (sTopActivity != activity)
        sTopActivity = activity;
    if (sApplicationContext == null && activity != null) {
        sApplicationContext = activity.getApplicationContext();
    }
}

From source file:com.citrus.sdk.database.DBHandler.java

public static boolean deleteDB(Activity activity) {
    return activity.getApplicationContext().deleteDatabase(DB_NAME);
}

From source file:Main.java

@SuppressLint("NewApi")
public static Bitmap decodeSampledBitmap(Uri uri, int reqWidth, int reqHeight, Activity act) {

    // First decode with inJustDecodeBounds=true to check dimensions
    InputStream is;//  ww  w.  j  av  a  2s .  c  o m
    try {
        is = act.getApplicationContext().getContentResolver().openInputStream(uri);
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(is, null, options);
        is.close(); //consider use is.mark and is.reset instead [TODO]

        // Calculate inSampleSize
        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

        // Decode bitmap with inSampleSize set
        //open input stream again
        is = act.getApplicationContext().getContentResolver().openInputStream(uri);
        options.inJustDecodeBounds = false;
        Bitmap ret = BitmapFactory.decodeStream(is, null, options);
        is.close();
        return ret;
    } catch (FileNotFoundException e) {
        Log.v(TAG, "File not found:" + uri.toString());
        e.printStackTrace();
    } catch (IOException e) {
        Log.v(TAG, "I/O exception with file:" + uri.toString());
        e.printStackTrace();
    }
    return null;
}

From source file:com.github.kimikage.uguisuan.WavePlayerService.java

public static void start(Activity activity) {

    UguisuAnne app = (UguisuAnne) (activity.getApplicationContext());
    if (app.getSourceWave() == null || app.getSourceWave().getPcm() == null) {
        update(-1);//from  ww  w .j a  v  a  2 s.  co  m
        return;
    }

    Intent intent = new Intent(activity, WavePlayerService.class);
    intent.putExtra(ARG_ACTION, Receiver.ACTION_START);
    activity.startService(intent);
}

From source file:Main.java

/**
 * Add account/*  w w  w. j av  a 2 s  .  c  o m*/
 * @param accountType accountType
 * @param authTokenType authTokenType
 * @param requiredFeatures requiredFeatures, could be <code>null</code>
 * @param options options, could be <code>null</code>
 * @param activity activity (cannot be <code>null</code>)
 */
public static void addAccount(String accountType, String authTokenType, String[] requiredFeatures,
        Bundle options, Activity activity) {
    if (activity == null) {
        throw new IllegalArgumentException("activity cannot be null");
    }
    final AccountManager accountManager = AccountManager.get(activity.getApplicationContext());
    accountManager.addAccount(accountType, authTokenType, requiredFeatures, options, activity, null, null);
}