Example usage for android.content Context getApplicationInfo

List of usage examples for android.content Context getApplicationInfo

Introduction

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

Prototype

public abstract ApplicationInfo getApplicationInfo();

Source Link

Document

Return the full application info for this context's package.

Usage

From source file:com.brainasylum.andruid.UniqueIdentifierManager.java

public synchronized void clearUdid(Context context) {
    // if permissions are granted, remove the identifier from
    // the storage bundle...
    if (canWriteExternalStorage(context)) {
        File file = new File(Environment.getExternalStorageDirectory() + "/" + FILE_DIR, FILE_NAME);
        if (file.exists()) {
            try {
                //
                FileInputStream fis = new FileInputStream(file);
                byte[] buffer = new byte[(int) file.length()];
                fis.read(buffer);//from www . j  a va  2s .c o m
                fis.close();
                JSONObject root = new JSONObject(new String(buffer));
                //
                String applicationName = context.getApplicationInfo().packageName;
                //
                if (root.has(applicationName)) {
                    JSONObject values = root.getJSONObject(applicationName);
                    if (values.has(_identifier.getKey())) {
                        // remove the identifier value and if it's the
                        // last one in the object remove the application
                        // node itself
                        values.remove(_identifier.getKey());
                        if (values.length() == 0) {
                            root.remove(applicationName);
                        }
                        //
                        FileOutputStream fos = new FileOutputStream(file);
                        fos.write(root.toString().getBytes());
                        fos.close();
                    }
                }
            } catch (IOException e) {
                Log.e(TAG, "I/O error with file " + file.getAbsolutePath(), e);
                e.printStackTrace();
            } catch (JSONException e) {
                Log.e(TAG, "JSON error with file " + file.getAbsolutePath(), e);
                e.printStackTrace();
            }
        }
    }
    // ... then remove it from the shared preferences...
    SharedPreferences prefs = context.getSharedPreferences(_identifier.getTag(), Context.MODE_PRIVATE);
    prefs.edit().remove(_identifier.getKey()).commit();
    // ... and clear the instance cached value.
    _udid = null;
}

From source file:android.support.v7.internal.widget.ActionBarOverlayLayout.java

private void init(Context context) {
    TypedArray ta = getContext().getTheme().obtainStyledAttributes(ATTRS);
    mActionBarHeight = ta.getDimensionPixelSize(0, 0);
    mWindowContentOverlay = ta.getDrawable(1);
    setWillNotDraw(mWindowContentOverlay == null);
    ta.recycle();/* w ww  . j av  a  2  s .com*/

    mIgnoreWindowContentOverlay = context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.KITKAT;

    mFlingEstimator = ScrollerCompat.create(context);
}

From source file:com.amazon.cordova.plugin.ADMMessageHandler.java

/**
 * Creates a notification when app is not running or is not in foreground. It puts the message info into the Intent
 * extra//from w w w  .j a  va2 s .  c  o  m
 * 
 * @param context
 * @param extras
 */
public void createNotification(Context context, Bundle extras) {
    NotificationManager notificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    String appName = getAppName(this);

    // reuse the intent so that we can combine multiple messages into extra
    if (notificationIntent == null) {
        notificationIntent = new Intent(this, ADMHandlerActivity.class);
    }
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notificationIntent.putExtra("pushBundle", extras);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final Builder notificationBuilder = new Notification.Builder(context);
    notificationBuilder.setSmallIcon(context.getApplicationInfo().icon).setWhen(System.currentTimeMillis())
            .setContentIntent(contentIntent);

    if (this.shouldShowMessageInNotification()) {
        String message = extras.getString(PushPlugin.MESSAGE);
        notificationBuilder.setContentText(Html.fromHtml(message).toString());
    } else {
        notificationBuilder.setContentText(this.defaultMessageTextInNotification());
    }

    String title = appName;
    notificationBuilder.setContentTitle(title).setTicker(title);
    notificationBuilder.setAutoCancel(true);
    // Because the ID remains unchanged, the existing notification is updated.
    notificationManager.notify((String) appName, NOTIFICATION_ID, notificationBuilder.getNotification());
}

From source file:com.cmgapps.android.util.CMGAppRater.java

/**
 * Shows a default {@link AlertDialog}/*  www .  ja v  a2  s  . c  o m*/
 *
 * @param context A Context to show the dialog
 */
public void show(final Context context) {
    if (context == null) {
        throw new IllegalArgumentException("context cannot be null");
    }

    if (Looper.getMainLooper().getThread() != Thread.currentThread()) {
        throw new RuntimeException("CMGAppRater.show() must be called from main thread");
    }

    if (mDialog != null && mDialog.isShowing())
        return;

    final Editor editor = mPref.edit();
    final PackageManager pm = context.getPackageManager();

    String appName;
    try {
        ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 0);
        appName = (String) pm.getApplicationLabel(ai);
    } catch (NameNotFoundException e) {
        LOGE(TAG, "Application name can not be found");
        appName = "App";
    }

    mDialog = new AlertDialog.Builder(context).setTitle(R.string.dialog_cmgrate_title)
            .setMessage(context.getString(R.string.dialog_cmgrate_message, appName)).setCancelable(false)
            .setIcon(context.getApplicationInfo().icon)
            .setPositiveButton(context.getString(R.string.dialog_cmgrate_ok),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            editor.putBoolean(APP_RATED, true);
                            Intent intent = new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("market://details?id=" + context.getPackageName()));
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(intent);

                            PreferenceEditorHelper.commit(editor);
                            dialog.dismiss();
                        }
                    })
            .setNegativeButton(R.string.dialog_cmgrate_no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    PreferenceEditorHelper.commit(editor.putBoolean(DECLINED_RATE, true));
                    dialog.dismiss();
                }
            }).setNeutralButton(R.string.dialog_cmgrate_later, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    PreferenceEditorHelper
                            .commit(editor.putLong(REMIND_LATER_DATE, System.currentTimeMillis()));
                    dialog.dismiss();
                }
            }).show();
    PreferenceEditorHelper.commit(editor);
}

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

static void startSDK(final Context c) {

    if (VDARSDKController.getInstance() != null) {
        return;//from w ww .  java  2  s  .c  om
    }

    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:android.support.v7.internal.widget.ActionBarView.java

public ActionBarView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;/*from  w ww. java 2  s . c  o m*/

    // Background is always provided by the container.
    setBackgroundResource(0);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar, R.attr.actionBarStyle, 0);

    ApplicationInfo appInfo = context.getApplicationInfo();
    PackageManager pm = context.getPackageManager();
    mNavigationMode = a.getInt(R.styleable.ActionBar_navigationMode, ActionBar.NAVIGATION_MODE_STANDARD);
    mTitle = a.getText(R.styleable.ActionBar_title);
    mSubtitle = a.getText(R.styleable.ActionBar_subtitle);
    mLogo = a.getDrawable(R.styleable.ActionBar_logo);
    if (mLogo == null) {
        if (Build.VERSION.SDK_INT >= 9) {
            if (context instanceof Activity) {
                try {
                    mLogo = pm.getActivityLogo(((Activity) context).getComponentName());
                } catch (NameNotFoundException e) {
                    Log.e(TAG, "Activity component name not found!", e);
                }
            }
            if (mLogo == null) {
                mLogo = appInfo.loadLogo(pm);
            }
        }
    }

    // TODO(trevorjohns): Should these use the android namespace
    mIcon = a.getDrawable(R.styleable.ActionBar_icon);
    if (mIcon == null) {
        if (context instanceof Activity) {
            try {
                mIcon = pm.getActivityIcon(((Activity) context).getComponentName());
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Activity component name not found!", e);
            }
        }
        if (mIcon == null) {
            mIcon = appInfo.loadIcon(pm);
        }
    }

    final LayoutInflater inflater = LayoutInflater.from(context);

    final int homeResId = a.getResourceId(R.styleable.ActionBar_homeLayout, R.layout.abc_action_bar_home);

    mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);

    mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
    mExpandedHomeLayout.setUp(true);
    mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
    mExpandedHomeLayout.setContentDescription(getResources().getText(R.string.abc_action_bar_up_description));

    mTitleStyleRes = a.getResourceId(R.styleable.ActionBar_titleTextStyle, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.ActionBar_subtitleTextStyle, 0);
    mProgressStyle = a.getResourceId(R.styleable.ActionBar_progressBarStyle, 0);
    mIndeterminateProgressStyle = a.getResourceId(R.styleable.ActionBar_indeterminateProgressStyle, 0);

    mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_progressBarPadding, 0);
    mItemPadding = a.getDimensionPixelOffset(R.styleable.ActionBar_itemPadding, 0);

    setDisplayOptions(a.getInt(R.styleable.ActionBar_displayOptions, DISPLAY_DEFAULT));

    final int customNavId = a.getResourceId(R.styleable.ActionBar_customNavigationLayout, 0);
    if (customNavId != 0) {
        mCustomNavView = (View) inflater.inflate(customNavId, this, false);
        mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
        setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
    }

    mContentHeight = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
    a.recycle();
    mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
    mHomeLayout.setOnClickListener(mUpClickListener);
    mHomeLayout.setClickable(true);
    mHomeLayout.setFocusable(true);

}

From source file:com.magnet.mmx.client.MMXClient.java

private boolean isApplicationDebuggable(Context context) {
    return ((context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) > 0);
}

From source file:com.actionbarsherlock.internal.widget.ActionBarView.java

public ActionBarView(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Background is always provided by the container.
    setBackgroundResource(0);//  w  w w .java  2s  .c  o m

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockActionBar, R.attr.actionBarStyle,
            0);

    ApplicationInfo appInfo = context.getApplicationInfo();
    PackageManager pm = context.getPackageManager();
    mNavigationMode = a.getInt(R.styleable.SherlockActionBar_navigationMode,
            ActionBar.NAVIGATION_MODE_STANDARD);
    mTitle = a.getText(R.styleable.SherlockActionBar_title);
    mSubtitle = a.getText(R.styleable.SherlockActionBar_subtitle);

    mLogo = a.getDrawable(R.styleable.SherlockActionBar_logo);
    if (mLogo == null) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            if (context instanceof Activity) {
                //Even though native methods existed in API 9 and 10 they don't work
                //so just parse the manifest to look for the logo pre-Honeycomb
                final int resId = loadLogoFromManifest((Activity) context);
                if (resId != 0) {
                    mLogo = context.getResources().getDrawable(resId);
                }
            }
        } else {
            if (context instanceof Activity) {
                try {
                    mLogo = pm.getActivityLogo(((Activity) context).getComponentName());
                } catch (NameNotFoundException e) {
                    Log.e(TAG, "Activity component name not found!", e);
                }
            }
            if (mLogo == null) {
                mLogo = appInfo.loadLogo(pm);
            }
        }
    }

    mIcon = a.getDrawable(R.styleable.SherlockActionBar_icon);
    if (mIcon == null) {
        if (context instanceof Activity) {
            try {
                mIcon = pm.getActivityIcon(((Activity) context).getComponentName());
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Activity component name not found!", e);
            }
        }
        if (mIcon == null) {
            mIcon = appInfo.loadIcon(pm);
        }
    }

    final LayoutInflater inflater = LayoutInflater.from(context);

    final int homeResId = a.getResourceId(R.styleable.SherlockActionBar_homeLayout,
            R.layout.abs__action_bar_home);

    mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);

    mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false);
    mExpandedHomeLayout.setUp(true);
    mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener);
    mExpandedHomeLayout.setContentDescription(getResources().getText(R.string.abs__action_bar_up_description));

    mTitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_titleTextStyle, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_subtitleTextStyle, 0);
    mProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_progressBarStyle, 0);
    mIndeterminateProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_indeterminateProgressStyle, 0);

    mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_progressBarPadding, 0);
    mItemPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_itemPadding, 0);

    setDisplayOptions(a.getInt(R.styleable.SherlockActionBar_displayOptions, DISPLAY_DEFAULT));

    final int customNavId = a.getResourceId(R.styleable.SherlockActionBar_customNavigationLayout, 0);
    if (customNavId != 0) {
        mCustomNavView = inflater.inflate(customNavId, this, false);
        mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD;
        setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM);
    }

    mContentHeight = a.getLayoutDimension(R.styleable.SherlockActionBar_height, 0);

    a.recycle();

    mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle);
    mHomeLayout.setOnClickListener(mUpClickListener);
    mHomeLayout.setClickable(true);
    mHomeLayout.setFocusable(true);
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

private void openPanel(final PanelFeatureState st, KeyEvent event) {
    // Already open, return
    if (st.isOpen || isDestroyed()) {
        return;/*from  w w w  .ja v  a  2 s .  co m*/
    }

    // Don't open an options panel for honeycomb apps on xlarge devices.
    // (The app should be using an action bar for menu items.)
    if (st.featureId == FEATURE_OPTIONS_PANEL) {
        Context context = mContext;
        Configuration config = context.getResources().getConfiguration();
        boolean isXLarge = (config.screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
        boolean isHoneycombApp = context
                .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB;

        if (isXLarge && isHoneycombApp) {
            return;
        }
    }

    Window.Callback cb = getWindowCallback();
    if ((cb != null) && (!cb.onMenuOpened(st.featureId, st.menu))) {
        // Callback doesn't want the menu to open, reset any state
        closePanel(st, true);
        return;
    }

    final WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    if (wm == null) {
        return;
    }

    // Prepare panel (should have been done before, but just in case)
    if (!preparePanel(st, event)) {
        return;
    }

    int width = WRAP_CONTENT;
    if (st.decorView == null || st.refreshDecorView) {
        if (st.decorView == null) {
            // Initialize the panel decor, this will populate st.decorView
            if (!initializePanelDecor(st) || (st.decorView == null))
                return;
        } else if (st.refreshDecorView && (st.decorView.getChildCount() > 0)) {
            // Decor needs refreshing, so remove its views
            st.decorView.removeAllViews();
        }

        // This will populate st.shownPanelView
        if (!initializePanelContent(st) || !st.hasPanelItems()) {
            return;
        }

        ViewGroup.LayoutParams lp = st.shownPanelView.getLayoutParams();
        if (lp == null) {
            lp = new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
        }

        int backgroundResId = st.background;
        st.decorView.setBackgroundResource(backgroundResId);

        ViewParent shownPanelParent = st.shownPanelView.getParent();
        if (shownPanelParent != null && shownPanelParent instanceof ViewGroup) {
            ((ViewGroup) shownPanelParent).removeView(st.shownPanelView);
        }
        st.decorView.addView(st.shownPanelView, lp);

        /*
         * Give focus to the view, if it or one of its children does not
         * already have it.
         */
        if (!st.shownPanelView.hasFocus()) {
            st.shownPanelView.requestFocus();
        }
    } else if (st.createdPanelView != null) {
        // If we already had a panel view, carry width=MATCH_PARENT through
        // as we did above when it was created.
        ViewGroup.LayoutParams lp = st.createdPanelView.getLayoutParams();
        if (lp != null && lp.width == ViewGroup.LayoutParams.MATCH_PARENT) {
            width = MATCH_PARENT;
        }
    }

    st.isHandled = false;

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(width, WRAP_CONTENT, st.x, st.y,
            WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL,
            WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH,
            PixelFormat.TRANSLUCENT);

    lp.gravity = st.gravity;
    lp.windowAnimations = st.windowAnimations;

    wm.addView(st.decorView, lp);
    st.isOpen = true;
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * This method reads the info form the App. Manifest file.
 * //  ww w .j  a v  a  2 s . c  om
 * @return
 */
public static int application_getVersionCode(Context context) {
    int res = -1;

    try {
        PackageInfo info = context.getPackageManager().getPackageInfo(context.getApplicationInfo().packageName,
                0);

        res = info.versionCode;
    } catch (Exception e) {
        if (LOG_ENABLE)
            Log.e("GET_APP_VERSION:ERROR", e.getMessage(), e);
    }

    return res;
}