Context getApplicationInfo - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Context getApplicationInfo method.

This code example shows how to use the following methods:getApplicationInfo, getPackageName, getResources, getSystemService
/* 
*    This file is part of GPSLogger for Android. 
* 
*    GPSLogger for Android is free software: you can redistribute it and/or modify 
*    it under the terms of the GNU General Public License as published by 
*    the Free Software Foundation, either version 2 of the License, or 
*    (at your option) any later version. 
* 
*    GPSLogger for Android is distributed in the hope that it will be useful, 
*    but WITHOUT ANY WARRANTY; without even the implied warranty of 
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
*    GNU General Public License for more details. 
* 
*    You should have received a copy of the GNU General Public License 
*    along with GPSLogger for Android.  If not, see <http://www.gnu.org/licenses/>. 
*/ 
 
package com.mendhak.gpslogger.senders.gdocs; 
 
import android.content.Context; 

8
CodeRank
This code example shows how to use the following methods:getApplicationInfo, getPackageManager
    private boolean mExpanded;
 
    HomeDisplay(Context context, ViewGroup parent, TypedArray attributes) {
        mContext = context;
        mMode = Mode.ICON;
        ApplicationInfo appInfo = context.getApplicationInfo();
        PackageManager pm = context.getPackageManager();
        loadLogo(attributes, pm, appInfo);
        loadIcon(attributes, pm, appInfo);
        createView(parent, attributes);
    } 
 
    private void loadLogo(TypedArray a, PackageManager pm, ApplicationInfo appInfo) {
        if (mContext instanceof Activity) {
            try { 
                mLogo = pm.getActivityLogo(((Activity) mContext).getComponentName());
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Failed to load app logo.", e);
            } 
        } 
7
CodeRank
This code example shows how to use the following methods:getApplicationInfo
        return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    } 
 
    @Provides 
    ApplicationInfo provideApplicationInfo(final Context context) {
        return context.getApplicationInfo();
    } 
 
    @Provides 
    AccountManager provideAccountManager(final Context context) {
        return AccountManager.get(context);
    } 
 
    @Provides 
    ClassLoader provideClassLoader(final Context context) {
        return context.getClassLoader();
    } 
 
    @Provides 
    NotificationManager provideNotificationManager(final Context context) {
7
CodeRank
This code example shows how to use the following methods:getApplicationInfo
    } 
 
    public boolean enableHomeButtonByDefault() { 
        // Older apps get the home button interaction enabled by default. 
        // Newer apps need to enable it explicitly. 
        return mContext.getApplicationInfo().targetSdkVersion <
                Build.VERSION_CODES.ICE_CREAM_SANDWICH;
    } 
 
    public int getStackedTabMaxWidth() { 
        return mContext.getResources().getDimensionPixelSize(
                R.dimen.action_bar_stacked_tab_max_width); 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getApplicationInfo, getResources
     * null, the default (viscous) interpolator will be used. "Flywheel" behavior will 
     * be in effect for apps targeting Honeycomb or newer. 
     */ 
    public Scroller(Context context, Interpolator interpolator) {
        this(context, interpolator,
                context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.HONEYCOMB);
    } 
 
    /** 
     * Create a Scroller with the specified interpolator. If the interpolator is 
     * null, the default (viscous) interpolator will be used. Specify whether or 
     * not to support progressive "flywheel" behavior in flinging. 
     */ 
    public Scroller(Context context, Interpolator interpolator, boolean flywheel) {
        mFinished = true;
        mInterpolator = interpolator;
        mPpi = context.getResources().getDisplayMetrics().density * 160.0f;
        mDeceleration = computeDeceleration(ViewConfiguration.getScrollFriction());
        mFlywheel = flywheel;
    } 

7
CodeRank
This code example shows how to use the following methods:getApplicationInfo
import android.provider.Settings.Secure; 
 
public class AppUtils { 
 
	public static boolean isDebuggable(Context ctx) {
		ApplicationInfo appInfo = ctx.getApplicationInfo();
		boolean debug = (appInfo.flags & FLAG_DEBUGGABLE) != 0;
		return debug;
	} 
 
	public static String getVersionName(Context ctx, boolean withVersionCode) {
		try { 
			PackageInfo pi = ctx.getPackageManager().getPackageInfo(
					ctx.getPackageName(), 0);
			if (withVersionCode) {
				return pi.versionName + " (" + pi.versionCode + ")";
			} else { 
				return pi.versionName;
			} 
		} catch (NameNotFoundException e) {
6
CodeRank
This code example shows how to use the following methods:getApplicationInfo
    } 
 
    public boolean enableHomeButtonByDefault() { 
        // Older apps get the home button interaction enabled by default. 
        // Newer apps need to enable it explicitly. 
        return mContext.getApplicationInfo().targetSdkVersion <
                Build.VERSION_CODES.ICE_CREAM_SANDWICH;
    } 
 
    public int getStackedTabMaxWidth() { 
        return mContext.getResources().getDimensionPixelSize(
                R.dimen.action_bar_stacked_tab_max_width); 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:getApplicationInfo
    public static File getStorageFolder(Context context) throws IOException {
        if (canWriteToStorage()) { 
            if (STORAGE_FOLDER == null) {
                STORAGE_FOLDER = Environment.getExternalStorageDirectory()
                        + "/Android/data/" 
                        + context.getApplicationInfo().packageName + "/";
                File folder = new File(STORAGE_FOLDER);
                folder.mkdirs();
            } 
 
            return new File(STORAGE_FOLDER);
        } else { 
            throw new IOException("Can not write to external storage.");
        } 
    } 
 
    public static File getTempFolder(Context context) throws IOException {
        File folder = new File(getStorageFolder(context), ".tmp/");
        folder.mkdirs();
        return folder;
6
CodeRank
This code example shows how to use the following methods:getApplicationInfo
 
		mArchivePath = ASSET_DB_PATH + "/" + name + ".zip";
		if (storageDirectory != null) {
			mDatabasePath = storageDirectory;
		} else { 
			mDatabasePath = context.getApplicationInfo().dataDir + "/databases";
		} 
		mUpgradePathFormat = ASSET_DB_PATH + "/" + name + "_upgrade_%s-%s.sql";
	} 
	 
	 /** 
     * Create a helper object to create, open, and/or manage a database in  
     * the application's default private data directory. 
     * This method always returns very quickly.  The database is not actually 
     * created or opened until one of {@link #getWritableDatabase} or 
     * {@link #getReadableDatabase} is called. 
     * 
     * @param context to use to open or create the database 
     * @param name of the database file 
     * @param factory to use for creating cursor objects, or null for the default 
6
CodeRank
This code example shows how to use the following methods:getApplicationInfo
     *  
     * @param context A Context used to check whether the application is 
     *                debuggable, this can be the application context 
     */ 
    public static ViewServer get(Context context) {
        ApplicationInfo info = context.getApplicationInfo();
        if (BUILD_TYPE_USER.equals(Build.TYPE) &&
                (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            if (sServer == null) {
                sServer = new ViewServer(ViewServer.VIEW_SERVER_DEFAULT_PORT);
            } 
     
            if (!sServer.isRunning()) {
                try { 
                    sServer.start();
                } catch (IOException e) {
                    Log.d(LOG_TAG, "Error:", e);
                } 
            } 
        } else { 
6
CodeRank

Related Context getApplicationInfo Questions & Answers:

getApplicationInfo Method Overview
Return the full application info for this context's package.
See Code Examples for other Android Context Methods: