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:com.github.rutvijkumar.twittfuse.Util.java

public static final void scheduleAlarm(Activity activity) {
    // Construct an intent that will execute the AlarmReceiver
    Intent intent = new Intent(activity.getApplicationContext(), OfflineTweetAlarmReceiver.class);

    // Create a PendingIntent to be triggered when the alarm goes off
    final PendingIntent pIntent = PendingIntent.getBroadcast(activity, OfflineTweetAlarmReceiver.REQUEST_CODE,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Setup periodic alarm every 10 seconds
    long firstMillis = System.currentTimeMillis(); // first run of alarm is
    // immediate/*from  w w w .j av  a 2 s  .co  m*/
    int intervalMillis = 10000; // 10 seconds
    AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
    alarm.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstMillis, intervalMillis, pIntent);
}

From source file:run.ace.IncomingMessages.java

public static Object getInstance(JSONArray message, Activity activity, CordovaWebView webView)
        throws JSONException {
    String fullTypeName = message.getString(2);

    if (fullTypeName.equals("android.content.Context")) {
        return activity.getApplicationContext();
    } else if (fullTypeName.equals("android.app.Activity")) {
        return activity;
    } else if (fullTypeName.equals("android.content.Intent")) {
        return NativeHost.intent;
    } else if (fullTypeName.equals("HostPage")) {
        return activity.findViewById(android.R.id.content);
    } else if (fullTypeName.equals("HostWebView")) {
        return webView.getView();
    } else if (fullTypeName.equals("PluginManager")) {
        return webView.getPluginManager();
    }/* w w w  . j a  v  a 2s .  c o  m*/

    throw new RuntimeException(fullTypeName + " is not a valid choice for getting an existing instance");
}

From source file:com.mediatek.contacts.activities.ActivitiesUtils.java

private static int getAvailableStorageCount(Activity activity) {
    int storageCount = 0;
    final StorageManager storageManager = (StorageManager) activity.getApplicationContext()
            .getSystemService(activity.STORAGE_SERVICE);
    if (null == storageManager) {
        Log.w(TAG, "[getAvailableStorageCount]storageManager is null,return 0.");
        return 0;
    }// w w  w. j a  va 2  s .c  o  m
    StorageVolume[] volumes = storageManager.getVolumeList();
    for (StorageVolume volume : volumes) {
        String path = volume.getPath();
        if (!Environment.MEDIA_MOUNTED.equals(storageManager.getVolumeState(path))) {
            continue;
        }
        storageCount++;
    }
    Log.d(TAG, "[getAvailableStorageCount]storageCount = " + storageCount);
    return storageCount;
}

From source file:de.baumann.quitsmoking.helper.helper_main.java

public static void openFile(Activity activity, File file, String string, View view) {

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Uri contentUri = FileProvider.getUriForFile(activity,
                activity.getApplicationContext().getPackageName() + ".provider", file);
        intent.setDataAndType(contentUri, string);

    } else {/*  ww  w.ja  va 2 s . c  o m*/
        intent.setDataAndType(Uri.fromFile(file), string);
    }

    try {
        activity.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Snackbar.make(view, R.string.toast_install_app, Snackbar.LENGTH_LONG).show();
    }
}

From source file:com.mediatek.contacts.activities.ActivitiesUtils.java

/** New Feature */
public static boolean checkSimNumberValid(Activity activity, String ssp) {
    if (ssp != null && !PhoneNumberUtils.isGlobalPhoneNumber(ssp)) {
        Toast.makeText(activity.getApplicationContext(), R.string.sim_invalid_number, Toast.LENGTH_SHORT)
                .show();//from   w w w .j a va2 s  .  co  m
        activity.finish();
        return true;
    }
    return false;
}

From source file:de.da_sense.moses.client.abstraction.ApkMethods.java

/**
 * Start an application by the name of the package.
 * /*  w w  w  .j av a2 s.c om*/
 * @param packageName package name of the app to start
 * @param baseActivity the base activity
 * @throws NameNotFoundException
 */
public static void startApplication(String packageName, Activity baseActivity) throws NameNotFoundException {
    if (baseActivity == null) {
        Log.e("ApkMethods", "the context was NULL for the package: " + packageName);
    }
    Intent intent = baseActivity.getApplicationContext().getPackageManager()
            .getLaunchIntentForPackage(packageName);
    Log.d("ApkMethods", "created intent, about to launch other application with packageName: " + packageName);
    baseActivity.startActivity(intent);
}

From source file:foundme.uniroma2.it.professore.HomeActivity.java

public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) {
    final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent,
            0);//from   w ww.  j  a v  a  2s  .  c  o  m

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

    //Stesso filtro del Manifest.
    filters[0] = new IntentFilter();
    filters[0].addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
    filters[0].addCategory(Intent.CATEGORY_DEFAULT);
    try {
        filters[0].addDataType(Variables_it.MIME_TEXT_PLAIN);
    } catch (IntentFilter.MalformedMimeTypeException e) {
        throw new RuntimeException(Variables_it.MIME_ERROR);
    }

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

From source file:menion.android.whereyougo.gui.extension.activity.CustomActivity.java

public static void setStatusbar(Activity activity) {
    try {// w  w w.  j  av a2s .  c  o m
        NotificationManager mNotificationManager = (NotificationManager) activity
                .getSystemService(Context.NOTIFICATION_SERVICE);
        // set statusbar
        if (Preferences.APPEARANCE_STATUSBAR) {
            Context context = activity.getApplicationContext();
            Intent intent = new Intent(context, menion.android.whereyougo.gui.activity.MainActivity.class);
            // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setAction(Intent.ACTION_MAIN);
            PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
            final int sdkVersion = Integer.parseInt(android.os.Build.VERSION.SDK);
            Notification notif = null;
            if (sdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
                notif = new Notification(R.drawable.ic_title_logo, A.getAppName(), System.currentTimeMillis());
                notif.setLatestEventInfo(activity, A.getAppName(), "", pIntent);
            } else {
                NotificationCompat.Builder builder = new NotificationCompat.Builder(activity)
                        .setContentTitle(A.getAppName()).setSmallIcon(R.drawable.ic_title_logo)
                        .setContentIntent(pIntent);
                notif = builder.build();
            }
            notif.flags = Notification.FLAG_ONGOING_EVENT;
            mNotificationManager.notify(0, notif);
        } else {
            mNotificationManager.cancel(0);
        }
    } catch (Exception e) {
        // Logger.e(TAG, "setStatusbar(" + activity + ")", e);
    }
}

From source file:im.vector.contacts.ContactsManager.java

/**
 * Tells if the contacts book access has been requested.
 * For android > M devices, it only tells if the permission has been granted.
 * @param activity the calling activity/*from  www. j a v  a  2  s .c o  m*/
 * @return true it was requested once
 */
public static boolean isContactBookAccessRequested(Activity activity) {
    if (Build.VERSION.SDK_INT >= 23) {
        return (PackageManager.PERMISSION_GRANTED == ContextCompat
                .checkSelfPermission(activity.getApplicationContext(), Manifest.permission.READ_CONTACTS));
    } else {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
        return preferences.contains(CONTACTS_BOOK_ACCESS_KEY);
    }
}

From source file:com.allen.mediautil.ImageTakerHelper.java

/**
 * ?/*from w  ww .ja v  a  2s.  c  o m*/
 * <p>
 * onActivityResult()?
 */
public static void openCamera(Activity activity, String authority) {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, getOutputPictureUri(activity.getApplicationContext(), authority));
    activity.startActivityForResult(intent, REQUEST_CAMERA);
}