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.amazonaws.mobileconnectors.s3.transferutility.TransferDBBase.java

/**
 * Constructs TransferdatabaseBase with the given Context.
 *
 * @param context A Context instance.//from   w  w w .  j  a v  a2  s  .  co  m
 */
public TransferDBBase(Context context) {
    this.context = context;
    final String mAuthority = context.getApplicationContext().getPackageName();
    databaseHelper = new TransferDatabaseHelper(this.context);
    database = databaseHelper.getWritableDatabase();
    contentUri = Uri.parse("content://" + mAuthority + "/" + BASE_PATH);
    uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);

    /*
     * The Uri of TRANSFERS is for all records in the table.
     */
    uriMatcher.addURI(mAuthority, BASE_PATH, TRANSFERS);

    /*
     * The Uri of TRANSFER_ID is for a single transfer record.
     */
    uriMatcher.addURI(mAuthority, BASE_PATH + "/#", TRANSFER_ID);

    /*
     * The Uri of TRANSFER_PART is for part records of a multipart upload.
     */
    uriMatcher.addURI(mAuthority, BASE_PATH + "/part/#", TRANSFER_PART);

    /*
     * The Uri of TRANSFER_STATE is for records with a specific state.
     */
    uriMatcher.addURI(mAuthority, BASE_PATH + "/state/*", TRANSFER_STATE);
}

From source file:com.fastbootmobile.rssdemo.PushReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "ACTION : " + intent.getAction()); // Debug log the intent "action"

    // Get the shared preferences for OwnPush keys
    SharedPreferences pref = context.getApplicationContext().getSharedPreferences(OwnPushClient.PREF_PUSH,
            Context.MODE_PRIVATE);

    if (intent.getAction().equals(OwnPushClient.INTENT_RECEIVE)) {

        // This is a push message

        Log.d(TAG, "Decrypt : " + intent.getExtras().getString(OwnPushClient.EXTRA_DATA));

        OwnPushCrypto fp = new OwnPushCrypto(); // Create a crypto object for decrypt

        // Get the app key pair from shared preferences (these have been confirmed by the register intent)
        OwnPushCrypto.AppKeyPair keys = fp.getKey(pref.getString(OwnPushClient.PREF_PUBLIC_KEY, ""),
                pref.getString(OwnPushClient.PREF_PRIVATE_KEY, ""));

        // Decrypt the message from the intent extra data
        String msg = fp.decryptFromIntent(intent.getExtras(), BuildConfig.APP_PUBLIC_KEY, keys);

        JSONObject jObj;/*  w  ww .  j  a  v a2 s  .c  om*/
        if (msg != null) {
            Log.e(TAG, "RSS : " + msg);

            try {
                // Decode the JOSN data in the message
                jObj = new JSONObject(msg);

                Intent i = new Intent(Intent.ACTION_VIEW); // Create the intent
                i.setData(Uri.parse(jObj.getString("link"))); // Set the data using URI (these are web links)

                // Convert to pending intent
                PendingIntent pIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), i,
                        0);

                // Create the notification
                Notification n = new Notification.Builder(context.getApplicationContext())
                        .setContentTitle("OwnPush RSS") // Main Title
                        .setContentText(jObj.getString("title")) // Set content
                        .setContentIntent(pIntent) // Add the pending intent
                        .setSmallIcon(R.drawable.ic_done).setAutoCancel(true) // Remove notification if opened
                        .build();

                n.defaults |= Notification.DEFAULT_SOUND; // Make some noise on push

                // Get the notification manager and display notification
                NotificationManager notificationManager = (NotificationManager) context
                        .getSystemService(Context.NOTIFICATION_SERVICE);
                notificationManager.notify(notification_num, n);

                // Increase the notification counter by 1
                notification_num++;

            } catch (Exception e) {
                return;
            }

        }
    }
}

From source file:net.kidlogger.kidlogger.SendTestReport.java

public SendTestReport(Context context, AttributeSet sett) {
    super(context, sett);
    this.context = context;

    setLayoutResource(R.layout.test_report);
    app = (TApplication) context.getApplicationContext();
}

From source file:com.contentful.vault.SqliteHelper.java

public SqliteHelper(Context context, SpaceHelper spaceHelper) {
    super(context, spaceHelper.getDatabaseName(), null, spaceHelper.getDatabaseVersion());
    this.context = context.getApplicationContext();
    this.spaceHelper = spaceHelper;
    copyDatabase();//from  w  w w. j a v a2s  . c  o m
}

From source file:com.sitexa.android.data.net.volley.VolleyApi.java

public VolleyApi(Context context) {
    this.context = context.getApplicationContext();
    this.requestQueue = Volley.newRequestQueue(this.context);
}

From source file:net.sf.sprockets.database.sqlite.DbOpenHelper.java

/**
 * Use a custom CursorFactory and/or DatabaseErrorHandler.
 *
 * @see #DbOpenHelper(Context, String, int, int, String)
 *//*w ww.  ja  va 2 s  .  co m*/
public DbOpenHelper(Context context, String name, CursorFactory factory, int version,
        DatabaseErrorHandler errorHandler, int createResId, String upgradeResBaseName) {
    super(context, name, factory, version, errorHandler);
    mContext = context.getApplicationContext();
    mCreate = createResId;
    mUpgrade = upgradeResBaseName;
}

From source file:com.friedran.appengine.dashboard.client.AppEngineDashboardAuthenticator.java

public AppEngineDashboardAuthenticator(Account account, DefaultHttpClient httpClient, Context context,
        OnUserInputRequiredCallback userInputRequiredCallback,
        PostAuthenticateCallback postAuthenticateCallback) {
    mAccount = account;//from  ww  w . j  a  v a 2s.  c  o  m
    mHttpClient = httpClient;
    mApplicationContext = context.getApplicationContext();
    mOnUserInputRequiredCallback = userInputRequiredCallback;
    mPostAuthenticateCallback = postAuthenticateCallback;
}

From source file:me.oriley.homage.Homage.java

private Homage(@NonNull Context context) {
    mContext = context.getApplicationContext();

    addLicense(APACHE_2_0, R.string.homage_license_apache_2_0_name, R.string.homage_license_apache_2_0_website,
            R.string.homage_license_apache_2_0_description);
    addLicense(BSD_2, R.string.homage_license_bsd_2_name, R.string.homage_license_bsd_2_website,
            R.string.homage_license_bsd_2_description);
    addLicense(BSD_3, R.string.homage_license_bsd_3_name, R.string.homage_license_bsd_3_website,
            R.string.homage_license_bsd_3_description);
    addLicense(CC0_1_0, R.string.homage_license_cc0_1_0_name, R.string.homage_license_cc0_1_0_website,
            R.string.homage_license_cc0_1_0_description);
    addLicense(CC_3_0, R.string.homage_license_cc_3_0_name, R.string.homage_license_cc_3_0_website,
            R.string.homage_license_cc_3_0_description);
    addLicense(LGPL_3_0, R.string.homage_license_lgpl_3_0_name, R.string.homage_license_lgpl_3_0_website,
            R.string.homage_license_lgpl_3_0_description);
    addLicense(MIT, R.string.homage_license_mit_name, R.string.homage_license_mit_website,
            R.string.homage_license_mit_description);
    addLicense(UNRECOGNISED, R.string.homage_empty_license, R.string.homage_empty_license,
            R.string.homage_unrecognised_license);
    addLicense(NONE, R.string.homage_empty_license, R.string.homage_empty_license,
            R.string.homage_empty_license);
}

From source file:com.partypoker.poker.engagement.reach.EngagementReachAgent.java

/**
 * Get the unique instance./*from   w  w w .j a va  2  s  . c  o m*/
 * @param context any valid context
 */
public static EngagementReachAgent getInstance(Context context) {
    /* Always check this even if we instantiate once to trigger null pointer in all cases */
    if (sInstance == null)
        sInstance = new EngagementReachAgent(context.getApplicationContext());
    return sInstance;
}

From source file:net.simno.klingar.playback.CastPlayback.java

CastPlayback(Context context) {
    appContext = context.getApplicationContext();
    CastSession castSession = CastContext.getSharedInstance(appContext).getSessionManager()
            .getCurrentCastSession();//from  ww  w  . j  ava2  s  .  c  o  m
    remoteMediaClient = castSession.getRemoteMediaClient();
    remoteMediaClientListener = new CastMediaClientListener();
}