Java Code Examples for android.content.pm.PackageManager.NameNotFoundException#printStackTrace()

The following examples show how to use android.content.pm.PackageManager.NameNotFoundException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageUtils.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
/**
 * get app version code
 *
 * @param context
 * @return
 */
public static int getAppVersionCode(Context context) {
    if (context != null) {
        PackageManager pm = context.getPackageManager();
        if (pm != null) {
            PackageInfo pi;
            try {
                pi = pm.getPackageInfo(context.getPackageName(), 0);
                if (pi != null) {
                    return pi.versionCode;
                }
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    return -1;
}
 
Example 2
Source File: AboutDialog.java    From color-picker-view with Apache License 2.0 6 votes vote down vote up
private void loadAbout(){
	
	PackageInfo pi = null;
	try {
		pi = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
	} catch (NameNotFoundException e) {
		e.printStackTrace();
	}
       
	mAppNameText.setText("ColorPickerView");	
	mVersionText.setText("Version" + " " + (pi != null ? pi.versionName : "null"));
		
	String s = "<b>Developed By:</b><br>Daniel Nilsson<br>";		
	mAboutText.setText(Html.fromHtml(s));

}
 
Example 3
Source File: Utilities.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
static Pair<String, Resources> findSystemApk(String action, PackageManager pm) {
    final Intent intent = new Intent(action);
    for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
        if (info.activityInfo != null &&
                (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            final String packageName = info.activityInfo.packageName;
            try {
                final Resources res = pm.getResourcesForApplication(packageName);
                return Pair.create(packageName, res);
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}
 
Example 4
Source File: About.java    From FlappyCow with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);
    
    // Version
    try {((TextView) findViewById(R.id.version_tv)).setText("" + getPackageManager().getPackageInfo(getPackageName(), 0).versionName);
    } catch (NameNotFoundException e) {e.printStackTrace();}
    
    // Backbutton
    ((Button)findViewById(R.id.back_button)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
}
 
Example 5
Source File: App.java    From weixin with Apache License 2.0 5 votes vote down vote up
/**
 * 获取版本code
 * 
 * @return
 */
public static int getVersionCode() {
	PackageManager packageManager = instance.getPackageManager();
	PackageInfo packageInfo = null;
	try {
		packageInfo = packageManager.getPackageInfo(instance.getPackageName(), 0);
	} catch (NameNotFoundException e) {
		e.printStackTrace();
	}
	return packageInfo.versionCode;
}
 
Example 6
Source File: IconCache.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
public void addCustomInfoToDataBase(Drawable icon, ItemInfo info, CharSequence title) {
    LauncherActivityInfo app = mLauncherApps.resolveActivity(info.getIntent(), info.user);
    final ComponentKey key = new ComponentKey(app.getComponentName(), app.getUser());
    CacheEntry entry = mCache.get(key);
    PackageInfo packageInfo = null;
    try {
        packageInfo = mPackageManager.getPackageInfo(
                app.getComponentName().getPackageName(), 0);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    // We can't reuse the entry if the high-res icon is not present.
    if (entry == null || entry.isLowResIcon || entry.icon == null) {
        entry = new CacheEntry();
    }
    entry.icon = LauncherIcons.createIconBitmap(icon, mContext);

    entry.title = title != null ? title : app.getLabel();

    entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser());
    mCache.put(key, entry);

    Bitmap lowResIcon = generateLowResIcon(entry.icon, mActivityBgColor);
    ContentValues values = newContentValues(entry.icon, lowResIcon, entry.title.toString(),
            app.getApplicationInfo().packageName);
    if (packageInfo != null) {
        addIconToDB(values, app.getComponentName(), packageInfo,
                mUserManager.getSerialNumberForUser(app.getUser()));
    }
}
 
Example 7
Source File: SampleAlarmReceiver.java    From play-apk-expansion with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    try {
        DownloaderClientMarshaller.startDownloadServiceIfRequired(context, intent, SampleDownloaderService.class);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}
 
Example 8
Source File: VDApplication.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
public String getAPPVersion() {
	if (mContext == null) {
		return "";
	}
	try {
		PackageInfo packInfo = mContext.getPackageManager().getPackageInfo(
				mContext.getPackageName(), 0);
		return packInfo.versionName;
	} catch (NameNotFoundException e) {
		e.printStackTrace();
	}
	return "";
}
 
Example 9
Source File: DownloaderService.java    From travelguide with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    try {
        mPackageInfo = getPackageManager().getPackageInfo(
                getPackageName(), 0);
        ApplicationInfo ai = getApplicationInfo();
        CharSequence applicationLabel = getPackageManager().getApplicationLabel(ai);
        mNotification = new DownloadNotification(this, applicationLabel);

    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
}
 
Example 10
Source File: AppbarAgent.java    From letv with Apache License 2.0 5 votes vote down vote up
private String b() {
    try {
        PackageInfo packageInfo = Global.getContext().getPackageManager().getPackageInfo("com.tencent.android.qqdownloader", 0);
        if (packageInfo == null) {
            return null;
        }
        return packageInfo.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 11
Source File: VersionUtil.java    From TvLauncher with Apache License 2.0 5 votes vote down vote up
/**
 * 获取软件版本号名称
 *
 * @param context
 * @return
 */
public static String getVersionCodeName(Context context) {
    String versionCode = "";
    try {
        // 获取软件版本号,对应AndroidManifest.xml下android:versionCode
        versionCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return versionCode;
}
 
Example 12
Source File: bt.java    From letv with Apache License 2.0 5 votes vote down vote up
public static String v(Context context) {
    PackageInfo packageInfo;
    String str = null;
    try {
        packageInfo = context.getPackageManager().getPackageInfo(u(context), 64);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        Object obj = str;
    }
    InputStream byteArrayInputStream = new ByteArrayInputStream(packageInfo.signatures[0].toByteArray());
    try {
        CertificateFactory instance = CertificateFactory.getInstance("X509");
    } catch (CertificateException e2) {
        e2.printStackTrace();
        obj = str;
    }
    try {
        X509Certificate x509Certificate = (X509Certificate) instance.generateCertificate(byteArrayInputStream);
    } catch (CertificateException e22) {
        e22.printStackTrace();
        obj = str;
    }
    try {
        str = a(MessageDigest.getInstance(CommonUtils.MD5_INSTANCE).digest(x509Certificate.getEncoded()));
    } catch (NoSuchAlgorithmException e3) {
        e3.printStackTrace();
    } catch (CertificateEncodingException e4) {
        e4.printStackTrace();
    }
    return str;
}
 
Example 13
Source File: CommonService.java    From KJFrameForAndroid with Apache License 2.0 5 votes vote down vote up
public static String getSign(Context context, String pkgName) {
    try {
        PackageInfo pis = context.getPackageManager().getPackageInfo(
                pkgName, PackageManager.GET_SIGNATURES);
        return MD5.hexdigest(pis.signatures[0].toByteArray());
    } catch (NameNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 14
Source File: BaseUtils.java    From orz with Apache License 2.0 5 votes vote down vote up
public static String getAppVersionName(Context context) {
    String versionName = "1.0";
    try {
        PackageInfo info = context.getPackageManager()
                .getPackageInfo(context.getPackageName(), 0);
        versionName = info.versionName;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return versionName;
}
 
Example 15
Source File: PackageUtil.java    From android-common with Apache License 2.0 5 votes vote down vote up
/**
 * 获取指定程序信息
 */
public static ApplicationInfo getApplicationInfo(Context context, String pkg) {
    try {
        return context.getPackageManager().getApplicationInfo(pkg, 0);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 16
Source File: APEZProvider.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
private boolean initIfNecessary() {
    if ( !mInit ) {
           Context ctx = getContext();
           PackageManager pm = ctx.getPackageManager();
           ProviderInfo pi = pm.resolveContentProvider(getAuthority(), PackageManager.GET_META_DATA);
           PackageInfo packInfo;
           try {
               packInfo = pm.getPackageInfo(ctx.getPackageName(), 0);
           } catch (NameNotFoundException e1) {
               e1.printStackTrace();
               return false;
           }
           int patchFileVersion;
           int mainFileVersion;
           int appVersionCode = packInfo.versionCode;
           String[] resourceFiles = null;
           if ( null != pi.metaData ) {
               mainFileVersion = pi.metaData.getInt("mainVersion", appVersionCode);
               patchFileVersion = pi.metaData.getInt("patchVersion", appVersionCode);
               String mainFileName = pi.metaData.getString("mainFilename", NO_FILE);
               if ( NO_FILE != mainFileName ) {
                   String patchFileName = pi.metaData.getString("patchFilename", NO_FILE);
                   if ( NO_FILE != patchFileName ) {
                       resourceFiles = new String[] { mainFileName, patchFileName };
                   } else {
                       resourceFiles = new String[] { mainFileName };
                   }
               }
           } else {
               mainFileVersion = patchFileVersion = appVersionCode;
           }
           try {
               if ( null == resourceFiles ) {
                   mAPKExtensionFile = APKExpansionSupport.getAPKExpansionZipFile(ctx, mainFileVersion, patchFileVersion);
               } else {
                   mAPKExtensionFile = APKExpansionSupport.getResourceZipFile(resourceFiles);
               }
               mInit = true;
               return true;
           } catch (IOException e) {
               e.printStackTrace();                
           }
    }
       return false;	    
}
 
Example 17
Source File: APEZProvider.java    From play-apk-expansion with Apache License 2.0 4 votes vote down vote up
private boolean initIfNecessary() {
    if (!mInit) {
        Context ctx = getContext();
        PackageManager pm = ctx.getPackageManager();
        ProviderInfo pi = pm.resolveContentProvider(getAuthority(),
                PackageManager.GET_META_DATA);
        PackageInfo packInfo;
        try {
            packInfo = pm.getPackageInfo(ctx.getPackageName(), 0);
        } catch (NameNotFoundException e1) {
            e1.printStackTrace();
            return false;
        }
        int patchFileVersion;
        int mainFileVersion;
        int appVersionCode = packInfo.versionCode;
        String[] resourceFiles = null;
        if (null != pi.metaData) {
            mainFileVersion = pi.metaData.getInt("mainVersion", appVersionCode);
            patchFileVersion = pi.metaData.getInt("patchVersion", appVersionCode);
            String mainFileName = pi.metaData.getString("mainFilename");
            if (null != mainFileName) {
                String patchFileName = pi.metaData.getString("patchFilename");
                if (null != patchFileName) {
                    resourceFiles = new String[] {
                            mainFileName, patchFileName
                    };
                } else {
                    resourceFiles = new String[] {
                            mainFileName
                    };
                }
            }
        } else {
            mainFileVersion = patchFileVersion = appVersionCode;
        }
        try {
            if (null == resourceFiles) {
                mAPKExtensionFile = APKExpansionSupport.getAPKExpansionZipFile(ctx,
                        mainFileVersion, patchFileVersion);
            } else {
                mAPKExtensionFile = APKExpansionSupport.getResourceZipFile(resourceFiles);
            }
            mInit = true;
            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
Example 18
Source File: TrafficCounterService.java    From android-download-manager with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate() {

	Log.i(TAG, "onCreate");

	connectivityManager = (ConnectivityManager) this
			.getSystemService(Context.CONNECTIVITY_SERVICE);

	telephonyManager = (TelephonyManager) this
			.getSystemService(Context.TELEPHONY_SERVICE);

	PackageManager packageManager = this.getPackageManager();
	ApplicationInfo info = null;
	try {
		info = packageManager.getApplicationInfo(this.getPackageName(),
				PackageManager.GET_META_DATA);
		mUid = info.uid;
	} catch (NameNotFoundException e) {
		e.printStackTrace();
	}

	timer = new Timer();
	timerTask = new TimerTask() {

		@Override
		public void run() {

			getTrafficStats();
		}
	};

	if (timer != null && timerTask != null) {
		preTx = curTx = TrafficStats.getUidTxBytes(mUid);
		preRx = curRx = TrafficStats.getUidRxBytes(mUid);
		Log.e(TAG, "cur" + curRx);
		timer.schedule(timerTask, 0, SAMPLING_RATE);

		// check the network operator is changed or not
		operatorName = telephonyManager.getNetworkOperatorName();
		if (!ConfigUtils.getString(this,
				ConfigUtils.KEY_Network_Operator_Name).equals(operatorName)) {
			ConfigUtils.setString(this,
					ConfigUtils.KEY_Network_Operator_Name, operatorName);
			ConfigUtils.setLong(this, ConfigUtils.KEY_RX_MOBILE, 0L);
			ConfigUtils.setLong(this, ConfigUtils.KEY_TX_MOBILE, 0L);
			// TODO Network operator has changed
		}
	}

}
 
Example 19
Source File: APEZProvider.java    From glide-support with The Unlicense 4 votes vote down vote up
private boolean initIfNecessary() {
    if ( !mInit ) {
           Context ctx = getContext();
           PackageManager pm = ctx.getPackageManager();
           ProviderInfo pi = pm.resolveContentProvider(getAuthority(), PackageManager.GET_META_DATA);
           PackageInfo packInfo;
           try {
               packInfo = pm.getPackageInfo(ctx.getPackageName(), 0);
           } catch (NameNotFoundException e1) {
               e1.printStackTrace();
               return false;
           }
           int patchFileVersion;
           int mainFileVersion;
           int appVersionCode = packInfo.versionCode;
           String[] resourceFiles = null;
           if ( null != pi.metaData ) {
               mainFileVersion = pi.metaData.getInt("mainVersion", appVersionCode);
               patchFileVersion = pi.metaData.getInt("patchVersion", appVersionCode);
            String mainFileName = pi.metaData.getString("mainFilename");
            mainFileName = mainFileName != null? mainFileName : NO_FILE;
            if ( NO_FILE != mainFileName ) {
                String patchFileName = pi.metaData.getString("patchFilename");
                patchFileName = patchFileName != null? patchFileName : NO_FILE;
	            if ( NO_FILE != patchFileName ) {
                       resourceFiles = new String[] { mainFileName, patchFileName };
                   } else {
                       resourceFiles = new String[] { mainFileName };
                   }
               }
           } else {
               mainFileVersion = patchFileVersion = appVersionCode;
           }
           try {
               if ( null == resourceFiles ) {
                   mAPKExtensionFile = APKExpansionSupport.getAPKExpansionZipFile(ctx, mainFileVersion, patchFileVersion);
               } else {
                   mAPKExtensionFile = APKExpansionSupport.getResourceZipFile(resourceFiles);
               }
               mInit = true;
               return true;
           } catch (IOException e) {
               e.printStackTrace();                
           }
    }
       return false;	    
}
 
Example 20
Source File: CheckUpdateThread.java    From cordova-plugin-app-update-demo with MIT License 3 votes vote down vote up
/**
 * 获取软件版本号
 * <p/>
 * It's weird, I don't know why.
 * <pre>
 * versionName -> versionCode
 * 0.0.1    ->  12
 * 0.3.4    ->  3042
 * 3.2.4    ->  302042
 * 12.234.221 -> 1436212
 * </pre>
 *
 * @param context
 * @return
 */
private int getVersionCodeLocal(Context context) {
    LOG.d(TAG, "getVersionCode..");

    int versionCode = 0;
    try {
        // 获取软件版本号,对应AndroidManifest.xml下android:versionCode
        versionCode = context.getPackageManager().getPackageInfo(packageName, 0).versionCode;
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return versionCode;
}