Context getPackageManager - 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 getPackageManager 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: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: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: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:bindService, getContentResolver, getPackageManager, getSharedPreferences
 
	private final SharedPreferences mPreferences; //Preferences to store the OpenUDID
	private final Random mRandom;
	 
	private OpenUDID_manager(Context context) {
		mPreferences =  context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
		mContext = context;
		mRandom = new Random();
		mReceivedOpenUDIDs = new HashMap<String, Integer>();
	} 
	 
	@Override 
  	public void onServiceConnected(ComponentName className, IBinder service) {
		//Get the OpenUDID from the remote service 
		try { 
			//Send a random number to the service 
			android.os.Parcel data = android.os.Parcel.obtain(); 
			data.writeInt(mRandom.nextInt());
			android.os.Parcel reply = android.os.Parcel.obtain(); 
			service.transact(1, android.os.Parcel.obtain(), reply, 0);

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPackageManager, getSystemService
public class IgnitedConnectivityChangedReceiver extends BroadcastReceiver {
 
    @Override 
    public void onReceive(Context context, Intent intent) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
 
        // Check if we are connected to an active data network. 
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        boolean isConnected = (activeNetwork != null) && activeNetwork.isConnectedOrConnecting();
 
        if (isConnected) {
            PackageManager pm = context.getPackageManager();
 
            ComponentName connectivityReceiver = new ComponentName(context,
                    IgnitedConnectivityChangedReceiver.class); 
            ComponentName locationReceiver = new ComponentName(context,
                    IgnitedLocationChangedReceiver.class); 
            ComponentName passiveLocationReceiver = new ComponentName(context,
                    IgnitedPassiveLocationChangedReceiver.class); 
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:getPackageManager, getString, startActivity
		intent.setData(Uri.parse(url));
		context.startActivity(intent);
	} 
 
	public static void startEmailActivity(Context context, int toResId, int subjectResId, int bodyResId) {
		startEmailActivity(context, context.getString(toResId), context.getString(subjectResId),
				context.getString(bodyResId));
	} 
 
	public static void startEmailActivity(Context context, String to, String subject, String body) {
		final Intent intent = new Intent(Intent.ACTION_SEND);
		intent.setType("message/rfc822");
 
		if (!TextUtils.isEmpty(to)) {
			intent.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
		} 
		if (!TextUtils.isEmpty(subject)) {
			intent.putExtra(Intent.EXTRA_SUBJECT, subject);
		} 
		if (!TextUtils.isEmpty(body)) {

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPackageManager, getPackageName
     */ 
    static String getDataDir(Context context) {
        /* On API 4 and later, you can just do this */ 
        // return context.getApplicationInfo().dataDir; 
 
        String packageName = context.getPackageName();
        PackageManager pm = context.getPackageManager();
        String dataDir = null;
        try { 
            dataDir = pm.getApplicationInfo(packageName, 0).dataDir;
        } catch (Exception e) {
            // Won't happen -- we know we're installed 
        } 
        return dataDir;
    } 
 
    private void setupBinDir() { 
        String dataDir = getDataDir(this);
        File binDir = new File(dataDir, "bin");
        if (!binDir.exists()) {
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPackageManager
 
    /** 
     * This round of tests confirms good operations with "zero" searchables found 
     */ 
    public void testSearchablesListEmpty() { 
        MyMockPackageManager mockPM = new MyMockPackageManager(mContext.getPackageManager());
        MyMockContext mockContext = new MyMockContext(mContext, mockPM);
 
        mockPM.setSearchablesMode(MyMockPackageManager.SEARCHABLES_MOCK_ZERO);
        Searchables searchables = new Searchables(mockContext, 0);
        searchables.buildSearchableList();
        ArrayList<SearchableInfo> searchablesList = searchables.getSearchablesList();
        assertNotNull(searchablesList);
        MoreAsserts.assertEmpty(searchablesList);
        ArrayList<SearchableInfo> global = searchables.getSearchablesInGlobalSearchList();
        MoreAsserts.assertEmpty(global);
    } 
     
    /** 
     * Generic health checker for an array of searchables. 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Context getPackageManager Questions & Answers:

Other Context getPackageManager Examples

86:		 * */
87:		private boolean isDeviceSupportCamera() {
88:			if (getApplicationContext().getPackageManager().hasSystemFeature(
89:					PackageManager.FEATURE_CAMERA)) {
90:				// this device has a camera

Read More

2:		 * */
3:		private boolean isDeviceSupportCamera() {
4:			if (getApplicationContext().getPackageManager().hasSystemFeature(
5:					PackageManager.FEATURE_CAMERA)) {
6:				// this device has a camera

Read More

getPackageManager Method Overview
Return PackageManager instance to find global package information.
See Code Examples for other Android Context Methods: