Context getPackageName - 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 getPackageName method.

This code example shows how to use the following methods:getClassLoader, getDir, getPackageManager, getPackageName
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPackageName, getSystemService, startService
     */ 
    static void runIntentInService(Context context, Intent intent) {
        if (mWakeLock == null) {
            // This is called from BroadcastReceiver, there is no init. 
            PowerManager pm = 
                (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, 
                    WAKELOCK_KEY);
        } 
        mWakeLock.acquire();
        
        // Use a naming convention, similar with how permissions and intents are  
        // used. Alternatives are introspection or an ugly use of statics.  
        String receiver = context.getPackageName() + ".C2DMReceiver";
        intent.setClassName(context, receiver);
         
        context.startService(intent);
 
    } 
     

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getContentResolver, getPackageManager, getPackageName
     *            the context 
     * @return the device's ANDROID_ID, or null if it could not be determined 
     * @see Secure#ANDROID_ID 
     */ 
    public static String getAndroidId(Context context) {
        String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        if (androidId == null) {
            // this happens on 1.6 and older 
            androidId = android.provider.Settings.System.getString(context.getContentResolver(),
                    android.provider.Settings.System.ANDROID_ID);
        } 
        return androidId;
    } 
 
    /** 
     * Same as {@link #getAndroidId(Context)}, but never returns null. 
     *  
     * @param context 
     *            the context 
     * @param fallbackValue 

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getContentResolver, getPackageName
	 
	private static AESObfuscator _obfuscator = null;
	 
	private static AESObfuscator getObfuscator(Context context, byte[] salt) {
		if (_obfuscator == null) {
			final String installationId = Installation.id(context);
			final String deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
			final String password = installationId + deviceId + context.getPackageName();
			_obfuscator = new AESObfuscator(salt, password);
		} 
		return _obfuscator;
	} 
		 
	public static String unobfuscate(Context context, byte[] salt, String obfuscated) {
		final AESObfuscator obfuscator = getObfuscator(context, salt);
		try { 
			return obfuscator.unobfuscate(obfuscated);
		} catch (ValidationException e) {
			Log.w(TAG, "Invalid obfuscated data or key");
		} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPackageManager, getPackageName
	public static String getPackageVersionName(final Context pContext) {
		return SystemUtils.getPackageInfo(pContext).versionName;
	} 
 
	public static String getPackageName(final Context pContext) {
		return pContext.getPackageName();
	} 
 
	public static String getApkFilePath(final Context pContext) throws NameNotFoundException {
		final PackageManager packMgmr = pContext.getPackageManager();
		return packMgmr.getApplicationInfo(SystemUtils.getPackageName(pContext), 0).sourceDir;
	} 
 
	private static PackageInfo getPackageInfo(final Context pContext) {
		try { 
			return pContext.getPackageManager().getPackageInfo(pContext.getPackageName(), 0);
		} catch (final NameNotFoundException e) {
			Debug.e(e);
			return null; 
		} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPackageName, getSystemService
     *  
     * @param context 
     * @return true if another application is above this one. 
     */ 
    public static boolean isApplicationBroughtToBackground(final Context context) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<RunningTaskInfo> tasks = am.getRunningTasks(1);
        if (!tasks.isEmpty()) {
            ComponentName topActivity = tasks.get(0).topActivity;
            if (!topActivity.getPackageName().equals(context.getPackageName())) {
                return true; 
            } 
        } 
 
        return false; 
    } 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPackageManager, getPackageName, getString, newInstance
	} 
 
	private <T> T doRequest(HttpRequestBase request, ResponseHandler<T> responseHandler) {
		mHttpRequest = request;
 
		AndroidHttpClient client = AndroidHttpClient.newInstance(getUserAgent(), mContext);
		AndroidHttpClient.modifyRequestToAcceptGzipResponse(mHttpRequest);
 
		HttpParams httpParameters = client.getParams();
		HttpConnectionParams.setSoTimeout(httpParameters, 100000);
 
		try { 
			return client.execute(mHttpRequest, responseHandler);
		} 
		catch (IOException e) {
			Log.e("Server request failed.", e);
		} 
		finally { 
			client.close();
		} 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getContentResolver, getPackageManager, getPackageName
     *            the context 
     * @return the device's ANDROID_ID, or null if it could not be determined 
     * @see Secure#ANDROID_ID 
     */ 
    public static String getAndroidId(Context context) {
        String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        if (androidId == null) {
            // this happens on 1.6 and older 
            androidId = android.provider.Settings.System.getString(context.getContentResolver(),
                    android.provider.Settings.System.ANDROID_ID);
        } 
        return androidId;
    } 
 
    /** 
     * Same as {@link #getAndroidId(Context)}, but never returns null. 
     *  
     * @param context 
     *            the context 
     * @param fallbackValue 

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPackageName, getResources, getString
     * @param resourceName 
     * @param resourceType 
     * @return 
     */ 
    public static int getDynamicResourceId(Context context, String resourceName, String resourceType) {
        return context.getResources().getIdentifier(resourceName, resourceType, context.getPackageName());
    } 
     
    /** 
     * Gets resource string dynamically 
     *  
     * @param context 
     * @param resourceName 
     * @return 
     */ 
    public static String getDynamicResourceString(Context context, String resourceName) {
        int resourceId = getDynamicResourceId(context, resourceName, "string");
        return context.getString(resourceId);
    } 
} 

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Context getPackageName Questions & Answers:

getPackageName Method Overview
Return the name of this application's package.
See Code Examples for other Android Context Methods: