Example usage for android.content Context getApplicationContext

List of usage examples for android.content Context getApplicationContext

Introduction

In this page you can find the example usage for android.content Context getApplicationContext.

Prototype

public abstract Context getApplicationContext();

Source Link

Document

Return the context of the single, global Application object of the current process.

Usage

From source file:com.pk.wallpapermanager.PkWallpaperManager.java

/**
 * Creates a global WallpaperManager instance.
 * /* w ww . j a v  a 2 s. c  o m*/
 * @param context
 */
public static void createInstance(Context context) {
    if (mInstance == null)
        mInstance = new PkWallpaperManager(context.getApplicationContext());
}

From source file:com.vidinoti.pixlive.PixLive.java

static void startSDK(final Context c) {

    if (VDARSDKController.getInstance() != null) {
        return;/*from  w  ww .  j ava  2  s  .  co  m*/
    }

    String storage = c.getApplicationContext().getFilesDir().getAbsolutePath() + "/pixliveSDK";

    String licenseKey = null;

    try {
        ApplicationInfo ai = c.getPackageManager().getApplicationInfo(c.getPackageName(),
                PackageManager.GET_META_DATA);
        Bundle bundle = ai.metaData;
        licenseKey = bundle.getString("com.vidinoti.pixlive.LicenseKey");
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    } catch (NullPointerException e) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    }

    if (storage == null || licenseKey == null) {
        Log.e(TAG, "Unable to start PixLive SDK without valid storage and license key.");
        return;
    }

    VDARSDKController.startSDK(c, storage, licenseKey);

    /* Comment out to disable QR code detection */
    VDARSDKController.getInstance().setEnableCodesRecognition(true);

    VDARSDKController.getInstance().setNotificationFactory(new NotificationFactory() {

        @Override
        public Notification createNotification(String title, String message, String notificationID) {

            Intent appIntent = c.getPackageManager().getLaunchIntentForPackage(c.getPackageName());

            appIntent.putExtra("nid", notificationID);
            appIntent.putExtra("remote", false);

            PendingIntent contentIntent = PendingIntent.getActivity(c, 0, appIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            ApplicationInfo ai = c.getApplicationInfo();

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c)
                    .setSmallIcon(ai.icon != 0 ? ai.icon : android.R.drawable.star_big_off)
                    .setContentTitle(title).setContentText(message).setContentIntent(contentIntent)
                    .setAutoCancel(true).setVibrate(new long[] { 100, 200, 200, 400 })
                    .setLights(Color.BLUE, 500, 1500);

            mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));

            return mBuilder.getNotification();
        }
    });
}

From source file:com.pk.wallpapermanager.PkWallpaperManager.java

/**
 * Returns the global instance of this WallpaperManager.
 * /*from   w w  w  .j  ava2  s  . co m*/
 * @param context
 * @return
 */
public static PkWallpaperManager getInstance(Context context) {
    if (mInstance == null)
        mInstance = new PkWallpaperManager(context.getApplicationContext());

    return mInstance;
}

From source file:com.facebook.FacebookSdk.java

/**
 * This method is public in order to be used by app events, please don't use directly.
 * @param context       The application context.
 * @param applicationId The application id.
 *///from w  ww  .  ja v a  2s  .c  o m
public static void publishInstallAsync(final Context context, final String applicationId) {
    // grab the application context ahead of time, since we will return to the caller
    // immediately.
    final Context applicationContext = context.getApplicationContext();
    FacebookSdk.getExecutor().execute(new Runnable() {
        @Override
        public void run() {
            FacebookSdk.publishInstallAndWaitForResponse(applicationContext, applicationId);
        }
    });
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.util.FileUtils.java

public static String sendMessageToServer(final Context ctx, final String path, final Long toId,
        final String toType, final Long timelineId, boolean retry, Long localId, String messageBody,
        Object messageApp) {/*from w  ww.jav  a  2s. c  om*/

    Account account = AccountUtils.getAccount(ctx.getApplicationContext(), true);
    AccountManager am = (AccountManager) ctx.getSystemService(Context.ACCOUNT_SERVICE);

    MessageSend m = new MessageSend();
    m.setBody(messageBody);
    m.setFrom(Long.valueOf(am.getUserData(account, JsonKeys.ID_STORED)));
    m.setTo(toId);
    m.setLocalId(localId);
    if (messageApp != null)
        m.setApp(messageApp);

    CommandStoreService cs = new CommandStoreService(ctx.getApplicationContext());
    try {
        boolean result = false;
        if (toType.equals(JsonKeys.GROUP)) {
            result = cs.createCommand(JsonParser.MessageSendToJson(m), Command.METHOD_SEND_MESSAGE_TO_GROUP,
                    path);
        } else if (toType.equals(JsonKeys.USER)) {
            result = cs.createCommand(JsonParser.MessageSendToJson(m), Command.METHOD_SEND_MESSAGE_TO_USER,
                    path);
        }

        if (result) {
            return ConstantKeys.SENDING_OK;
        } else {
            return ConstantKeys.SENDING_OFFLINE;
        }
    } catch (JSONException e) {
        log.error("Cannot create command", e);
        return ConstantKeys.SENDING_FAIL;
    }
}

From source file:com.lazy.gank.logging.Logcat.java

/**
 * @param context/*from ww w . j a  va2s .c om*/
 * @param config
 */
public static void initialize(@NonNull Context context, @NonNull Config config) {
    mContext = context.getApplicationContext();
    if (config.logSavePath == null || config.logSavePath.trim().equals("")) {
        defaultConfig();
    } else {
        checkSaveLogPath(config.logSavePath);
    }
    if (config.logCatLogLevel != null) {
        m_cLogCatShowLogType = config.logCatLogLevel;
    }
    if (config.fileLogLevel != null) {
        m_cFileSaveLogType = config.fileLogLevel;
        if (m_cFileSaveLogType == NOT_SHOW_LOG)
            mSingleExecutors = null; //Recycle
    }

}

From source file:com.facebook.internal.Utility.java

/**
 * Returns the name of the current activity if the context is an activity, otherwise return "unknown"
 */// w ww.  j  a  va2s  .com
public static String getActivityName(Context context) {
    if (context == null) {
        return "null";
    } else if (context == context.getApplicationContext()) {
        return "unknown";
    } else {
        return context.getClass().getSimpleName();
    }
}

From source file:com.apptentive.android.sdk.module.engagement.interaction.InteractionManager.java

public static void asyncFetchAndStoreInteractions(final Context context) {

    if (!isPollForInteractions(context)) {
        Log.v("Interaction polling is disabled.");
        return;//from w w  w.  j  av  a 2 s  .c o  m
    }

    if (hasCacheExpired(context)) {
        Log.d("Interaction cache has expired. Fetching new interactions.");
        Thread thread = new Thread() {
            public void run() {
                fetchAndStoreInteractions(context);
            }
        };
        Thread.UncaughtExceptionHandler handler = new Thread.UncaughtExceptionHandler() {
            @Override
            public void uncaughtException(Thread thread, Throwable throwable) {
                Log.w("UncaughtException in InteractionManager.", throwable);
                MetricModule.sendError(context.getApplicationContext(), throwable, null, null);
            }
        };
        thread.setUncaughtExceptionHandler(handler);
        thread.setName("Apptentive-FetchInteractions");
        thread.start();
    } else {
        Log.d("Interaction cache has not expired. Using existing interactions.");
    }
}

From source file:com.activate.baidu.push.PushModule.java

private static boolean a(Context context) {
    boolean flag = true;
    try {//from  w  w  w . j a  v  a  2 s  .  c  o m
        ActivityManager activitymanager = (ActivityManager) context.getSystemService("activity");
        int i = Process.myPid();
        Iterator iterator = activitymanager.getRunningAppProcesses().iterator();
        do {
            if (!iterator.hasNext())
                break;
            android.app.ActivityManager.RunningAppProcessInfo runningappprocessinfo = (android.app.ActivityManager.RunningAppProcessInfo) iterator
                    .next();
            if (runningappprocessinfo.pid == i) {
                String s = c(context);
                if (runningappprocessinfo.processName.equalsIgnoreCase(s)) {
                    boolean flag1 = b(context.getApplicationContext());
                    if (!flag1)
                        Process.killProcess(i);
                }
            }
        } while (true);
    } catch (Exception exception) {
        flag = false;
        exception.printStackTrace();
    }
    return flag;
}

From source file:com.facebook.Settings.java

/**
 * Initialize SDK//  w  w w. ja v a2 s.c o m
 * This function will be called once in the application, it is tried to be called as early as possible;
 * This is the place to register broadcast listeners.
 */
public static synchronized void sdkInitialize(Context context) {
    if (sdkInitialized == true) {
        return;
    }

    // Make sure we've loaded default settings if we haven't already.
    Settings.loadDefaultsFromMetadataIfNeeded(context);
    // Load app settings from network so that dialog configs are available
    Utility.loadAppSettingsAsync(context, Settings.getApplicationId());

    BoltsMeasurementEventListener.getInstance(context.getApplicationContext());
    sdkInitialized = true;
}