Java Code Examples for android.content.pm.PackageInfo

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/activity/.

Source file: AboutActivity.java

  21 
vote

private String getVersion(){
  try {
    PackageManager packageManager=getPackageManager();
    PackageInfo packageInfo=packageManager.getPackageInfo(getPackageName(),0);
    return packageInfo.versionName;
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.e(Constants.TAG,"Error while fetching app version",e);
    return "?";
  }
}
 

Example 2

From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.

Source file: AboutDialog.java

  18 
vote

public static AlertDialog create(Context context) throws NameNotFoundException {
  PackageInfo pInfo=context.getPackageManager().getPackageInfo(context.getPackageName(),PackageManager.GET_META_DATA);
  String versionInfo=pInfo.versionName;
  String aboutTitle=String.format("About %s",context.getString(R.string.app_name));
  String versionString=String.format("Version: %s",versionInfo);
  String aboutText=context.getResources().getString(R.string.about_dialog_text);
  final TextView message=new TextView(context);
  final SpannableString s=new SpannableString(aboutText);
  message.setPadding(5,5,5,5);
  message.setText(versionString + "\n\n" + s);
  Linkify.addLinks(message,Linkify.ALL);
  message.setTextColor(Color.WHITE);
  return new AlertDialog.Builder(context).setTitle(aboutTitle).setCancelable(true).setIcon(R.drawable.icon).setPositiveButton(context.getString(android.R.string.ok),null).setView(message).create();
}
 

Example 3

From project and-bible, under directory /AndBible/src/net/bible/service/common/.

Source file: CommonUtils.java

  18 
vote

public static String getApplicationVersionName(){
  String versionName=null;
  try {
    PackageManager manager=BibleApplication.getApplication().getPackageManager();
    PackageInfo info=manager.getPackageInfo(BibleApplication.getApplication().getPackageName(),0);
    versionName=info.versionName;
  }
 catch (  final NameNotFoundException e) {
    Log.e(TAG,"Error getting package name.",e);
    versionName="Error";
  }
  return versionName;
}
 

Example 4

From project andlytics, under directory /src/com/github/andlyticsproject/.

Source file: BaseActivity.java

  18 
vote

public static int getAppVersionCode(Context context){
  try {
    PackageInfo pinfo=context.getPackageManager().getPackageInfo(context.getPackageName(),0);
    return pinfo.versionCode;
  }
 catch (  NameNotFoundException e) {
    Log.e(AndlyticsApp.class.getSimpleName(),"unable to read version code",e);
  }
  return 0;
}
 

Example 5

From project Android, under directory /AndroidNolesCore/src/util/.

Source file: XMLParserConnection.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  String versionName="unknown";
  int versionCode=0;
  try {
    final PackageInfo info=context.getPackageManager().getPackageInfo(context.getPackageName(),0);
    versionName=info.versionName;
    versionCode=info.versionCode;
  }
 catch (  NameNotFoundException ignored) {
  }
  return context.getPackageName() + "/" + versionName+ " ("+ versionCode+ ") (gzip)";
}
 

Example 6

From project android-context, under directory /defunct/.

Source file: PrefsActivity.java

  18 
vote

public static String getVersion(Context context){
  String version="1.0";
  try {
    PackageInfo pi=context.getPackageManager().getPackageInfo(context.getPackageName(),0);
    version=pi.versionName;
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.e(TAG,"Package name not found",e);
  }
  return version;
}
 

Example 7

From project android-shuffle, under directory /client/src/org/dodgybits/shuffle/android/core/activity/.

Source file: TopLevelActivity.java

  18 
vote

private void addVersionToTitle(){
  String title=getTitle().toString();
  try {
    PackageInfo info=getPackageManager().getPackageInfo(getPackageName(),0);
    title+=" " + info.versionName;
    setTitle(title);
  }
 catch (  AndroidException e) {
    Log.e(cTag,"Failed to add version to title: " + e.getMessage());
  }
}
 

Example 8

From project android-tether, under directory /src/og/android/tether/.

Source file: TetherApplication.java

  18 
vote

public int getVersionNumber(){
  int version=-1;
  try {
    PackageInfo pi=getPackageManager().getPackageInfo(getPackageName(),0);
    version=pi.versionCode;
  }
 catch (  Exception e) {
    Log.e(MSG_TAG,"Package name not found",e);
  }
  return version;
}
 

Example 9

From project android-voip-service, under directory /src/main/java/net/chrislehmann/sipservice/service/.

Source file: SipService.java

  18 
vote

private void dumpInstalledLinphoneInformation(){
  PackageInfo info=null;
  try {
    info=getPackageManager().getPackageInfo(getPackageName(),0);
  }
 catch (  PackageManager.NameNotFoundException nnfe) {
  }
  if (info != null) {
    org.linphone.core.Log.i("Linphone version is ",info.versionCode);
  }
 else {
    org.linphone.core.Log.i("Linphone version is unknown");
  }
}
 

Example 10

From project android_packages_apps_FileManager, under directory /src/org/openintents/distribution/.

Source file: UpdateDialog.java

  18 
vote

/** 
 * Check if no updater application is installed.
 * @param context
 * @return
 */
public static boolean isUpdateMenuNecessary(Context context){
  PackageInfo pi=null;
  for (int i=0; i < UPDATE_CHECKER.length; i++) {
    try {
      pi=context.getPackageManager().getPackageInfo(UPDATE_CHECKER[i],0);
    }
 catch (    NameNotFoundException e) {
    }
    if (pi != null && !DEBUG_NO_MARKET) {
      return false;
    }
  }
  return true;
}
 

Example 11

From project android_packages_apps_Gallery2, under directory /gallerycommon/src/com/android/gallery3d/common/.

Source file: HttpClientFactory.java

  18 
vote

private static String getUserAgent(Context context){
  if (sUserAgent == null) {
    PackageInfo pi;
    try {
      pi=context.getPackageManager().getPackageInfo(context.getPackageName(),0);
    }
 catch (    NameNotFoundException e) {
      throw new IllegalStateException("getPackageInfo failed");
    }
    sUserAgent=String.format("%s/%s; %s/%s/%s/%s; %s/%s/%s",pi.packageName,pi.versionName,Build.BRAND,Build.DEVICE,Build.MODEL,Build.ID,Build.VERSION.SDK,Build.VERSION.RELEASE,Build.VERSION.INCREMENTAL);
  }
  return sUserAgent;
}
 

Example 12

From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/.

Source file: QsbApplication.java

  18 
vote

public int getVersionCode(){
  if (mVersionCode == 0) {
    try {
      PackageManager pm=getContext().getPackageManager();
      PackageInfo pkgInfo=pm.getPackageInfo(getContext().getPackageName(),0);
      mVersionCode=pkgInfo.versionCode;
    }
 catch (    PackageManager.NameNotFoundException ex) {
      throw new RuntimeException(ex);
    }
  }
  return mVersionCode;
}
 

Example 13

From project android_packages_apps_Superuser, under directory /src/com/noshufou/android/su/util/.

Source file: Util.java

  18 
vote

public static VersionInfo getSuperuserVersionInfo(Context context){
  VersionInfo info=new VersionInfo();
  PackageManager pm=context.getPackageManager();
  try {
    PackageInfo pInfo=pm.getPackageInfo(context.getPackageName(),PackageManager.GET_META_DATA);
    info.version=pInfo.versionName;
    info.versionCode=pInfo.versionCode;
  }
 catch (  NameNotFoundException e) {
    Log.e(TAG,"Superuser is not installed?",e);
  }
  return info;
}
 

Example 14

From project androlog, under directory /androlog/src/main/java/de/akquinet/android/androlog/reporter/.

Source file: Report.java

  18 
vote

/** 
 * Adds the application data to the report.
 * @param report the report
 * @throws JSONException if the application data cannot be added
 */
private void addApplicationData(JSONObject report) throws JSONException {
  JSONObject app=new JSONObject();
  app.put("package",context.getPackageName());
  try {
    PackageInfo info=context.getPackageManager().getPackageInfo(context.getPackageName(),0);
    app.put("versionCode",info.versionCode);
    app.put("versionName",info.versionName);
  }
 catch (  NameNotFoundException e) {
  }
  report.put("application",app);
}
 

Example 15

From project Anki-Android, under directory /src/com/ichi2/anki/.

Source file: AnkiDroidApp.java

  18 
vote

/** 
 * Get package name as defined in the manifest.
 * @return the package name.
 */
public static String getPkgName(){
  String pkgName=TAG;
  Context context=sInstance.getApplicationContext();
  try {
    PackageInfo pInfo=context.getPackageManager().getPackageInfo(context.getPackageName(),0);
    pkgName=context.getString(pInfo.applicationInfo.labelRes);
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.e(TAG,"Couldn't find package named " + context.getPackageName(),e);
  }
  return pkgName;
}
 

Example 16

From project AnySoftKeyboard, under directory /src/com/anysoftkeyboard/addons/.

Source file: AddOnsFactory.java

  18 
vote

protected boolean isPackageContainAnAddon(Context context,String packageNameSchemePart) throws NameNotFoundException {
  PackageInfo newPackage=context.getPackageManager().getPackageInfo(packageNameSchemePart,PackageManager.GET_RECEIVERS + PackageManager.GET_META_DATA);
  if (newPackage.receivers != null) {
    ActivityInfo[] receivers=newPackage.receivers;
    for (    ActivityInfo aReceiver : receivers) {
      if (aReceiver == null || aReceiver.applicationInfo == null || !aReceiver.enabled || !aReceiver.applicationInfo.enabled)       continue;
      final XmlPullParser xml=aReceiver.loadXmlMetaData(context.getPackageManager(),RECEIVER_META_DATA);
      if (xml != null) {
        return true;
      }
    }
  }
  return false;
}
 

Example 17

From project apg, under directory /src/org/thialfihar/android/apg/.

Source file: Apg.java

  18 
vote

public static boolean isReleaseVersion(Context context){
  try {
    PackageInfo pi=context.getPackageManager().getPackageInfo(mApgPackageName,0);
    if (pi.versionCode % 100 == 99) {
      return true;
    }
 else {
      return false;
    }
  }
 catch (  NameNotFoundException e) {
    return false;
  }
}
 

Example 18

From project apps-for-android, under directory /BTClickLinkCompete/src/net/clc/bt/.

Source file: ConnectionService.java

  18 
vote

public int getVersion() throws RemoteException {
  try {
    PackageManager pm=mSelf.getPackageManager();
    PackageInfo pInfo=pm.getPackageInfo(mSelf.getPackageName(),0);
    return pInfo.versionCode;
  }
 catch (  NameNotFoundException e) {
    Log.e(TAG,"NameNotFoundException in getVersion",e);
  }
  return 0;
}
 

Example 19

From project AquaNotesTest, under directory /src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 20

From project be.norio.twunch.android, under directory /src/be/norio/twunch/android/service/.

Source file: SyncService.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 21

From project BombusLime, under directory /src/org/bombusim/lime/.

Source file: Lime.java

  18 
vote

public String getVersion(){
  if (version == null) {
    try {
      PackageInfo pinfo=getPackageManager().getPackageInfo(getPackageName(),0);
      version=pinfo.versionName + "." + gitVersion();
    }
 catch (    NameNotFoundException e) {
      version="unknown";
    }
  }
  return version;
}
 

Example 22

From project bookmarktodesktop-android-application, under directory /src/be/vbsteven/bmtodesk/.

Source file: Licensing.java

  18 
vote

public static boolean verify(Context context){
  PackageManager pm=context.getPackageManager();
  try {
    PackageInfo info=pm.getPackageInfo("be.vbsteven.bmtodesklicense",0);
    return true;
  }
 catch (  NameNotFoundException e) {
    return false;
  }
}
 

Example 23

From project Catroid-maven-playground, under directory /src/main/java/at/tugraz/ist/catroid/utils/.

Source file: Utils.java

  18 
vote

public static int getVersionCode(Context context){
  int versionCode=-1;
  try {
    PackageInfo packageInfo=context.getPackageManager().getPackageInfo(context.getPackageName(),PackageManager.GET_META_DATA);
    versionCode=packageInfo.versionCode;
  }
 catch (  NameNotFoundException nameNotFoundException) {
    Log.e(TAG,"Name not found",nameNotFoundException);
  }
  return versionCode;
}
 

Example 24

From project CoinFlip, under directory /src/com/banasiak/coinflip/.

Source file: Util.java

  18 
vote

public List<PackageInfo> findExternalPackages(){
  Log.d(TAG,"findExternalPackages()");
  final List<PackageInfo> packageInfo=mContext.getPackageManager().getInstalledPackages(0);
  for (int i=0, n=packageInfo.size() - 1; i <= n; --n) {
    final PackageInfo info=packageInfo.get(n);
    if (!isExternalCoinPackage(info)) {
      packageInfo.remove(n);
    }
  }
  return packageInfo;
}
 

Example 25

From project conference-mobile-app, under directory /android-app/src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 26

From project daily-money, under directory /dailymoney/src/com/bottleworks/dailymoney/context/.

Source file: Contexts.java

  18 
vote

/** 
 * for ui context only
 * @return
 */
public String getApplicationVersionName(){
  if (uiActivity != null) {
    Application app=(uiActivity).getApplication();
    String name=app.getPackageName();
    PackageInfo pi;
    try {
      pi=app.getPackageManager().getPackageInfo(name,0);
      return pi.versionName;
    }
 catch (    NameNotFoundException e) {
    }
  }
  return "";
}
 

Example 27

From project dccsched, under directory /src/com/underhilllabs/dccsched/service/.

Source file: SyncService.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 28

From project dcnyc10-android, under directory /android/src/com/lullabot/android/apps/iosched/service/.

Source file: SyncService.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 29

From project DeskSMS, under directory /DeskSMS/src/com/koushikdutta/desktopsms/.

Source file: DesktopSMSApplication.java

  18 
vote

void doStuff(){
  super.onCreate();
  try {
    PackageInfo pinfo=getPackageManager().getPackageInfo(getPackageName(),0);
    mVersionCode=pinfo.versionCode;
    ClockworkModBillingClient.init(this,"[email protected]",CLOCKWORKMOD_PUBLICKEY,MARKET_PUBLICKEY,Helper.SANDBOX).refreshMarketPurchases();
  }
 catch (  Exception ex) {
    ex.printStackTrace();
  }
}
 

Example 30

From project devoxx-france-android-in-fine, under directory /src/com/infine/android/devoxx/service/.

Source file: RestService.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 31

From project Diktofon, under directory /app/src/kaljurand_at_gmail_dot_com/diktofon/activity/.

Source file: AboutActivity.java

  18 
vote

private String getVersionName(){
  PackageInfo info=getPackageInfo();
  if (info == null) {
    return "?.?.?";
  }
  return info.versionName;
}
 

Example 32

From project dmix, under directory /MPDroid/src/com/namelessdev/mpdroid/.

Source file: AboutActivity.java

  18 
vote

public static String getVersionName(Context context,Class<Activity> cls){
  try {
    ComponentName comp=new ComponentName(context,cls);
    PackageInfo pinfo=context.getPackageManager().getPackageInfo(comp.getPackageName(),0);
    return pinfo.versionName;
  }
 catch (  android.content.pm.PackageManager.NameNotFoundException e) {
    return null;
  }
}
 

Example 33

From project dreamDroid, under directory /src/net/reichholf/dreamdroid/.

Source file: DreamDroid.java

  18 
vote

/** 
 * @param context
 * @return
 */
public static String getVersionString(Context context){
  try {
    ComponentName comp=new ComponentName(context,context.getClass());
    PackageInfo pinfo=context.getPackageManager().getPackageInfo(comp.getPackageName(),0);
    return "dreamDroid " + pinfo.versionName + "\n? Stephan Reichholf\[email protected]";
  }
 catch (  android.content.pm.PackageManager.NameNotFoundException e) {
    return "dreamDroid\n? 2010 Stephan Reichholf\[email protected]";
  }
}
 

Example 34

From project droid-fu, under directory /src/main/java/com/github/droidfu/support/.

Source file: DiagnosticSupport.java

  18 
vote

public static String getApplicationVersionString(Context context){
  try {
    PackageManager pm=context.getPackageManager();
    PackageInfo info=pm.getPackageInfo(context.getPackageName(),0);
    return "v" + info.versionName;
  }
 catch (  Exception e) {
    e.printStackTrace();
    return null;
  }
}
 

Example 35

From project ElectricSleep, under directory /src/com/androsz/electricsleepbeta/app/.

Source file: SettingsActivity.java

  18 
vote

@Override public void onCreate(final Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  if (getNeedToLoadOldStylePreferences()) {
    try {
      PackageInfo packageInfo=getPackageManager().getPackageInfo(getPackageName(),0);
      findPreference(getText(R.string.title_version)).setSummary(packageInfo.versionName);
    }
 catch (    NameNotFoundException e) {
      this.trackEvent("Retrieving VersionName failed for SettingsActivity-oldstyle.",1);
    }
  }
}
 

Example 36

From project eoit, under directory /EOIT/src/fr/eoit/activity/.

Source file: GoogleAnalyticsActivity.java

  18 
vote

@Override protected void onStart(){
  super.onStart();
  EasyTracker.getTracker().trackActivityStart(this);
  EasyTracker.getTracker().trackPageView(getClass().getSimpleName());
  EasyTracker.getTracker().setCustomVar(1,"AndroidVersion",String.valueOf(Build.VERSION.SDK_INT));
  try {
    PackageInfo pInfo=getPackageManager().getPackageInfo(getPackageName(),0);
    EasyTracker.getTracker().setCustomVar(2,"EOITVersion",pInfo.versionName);
  }
 catch (  NameNotFoundException e) {
  }
}
 

Example 37

From project FBReaderJ, under directory /src/org/geometerplus/zlibrary/ui/android/error/.

Source file: ErrorUtil.java

  18 
vote

public String getVersionName(){
  try {
    final PackageInfo info=myContext.getPackageManager().getPackageInfo(myContext.getPackageName(),0);
    return info.versionName + " (" + info.versionCode+ ")";
  }
 catch (  Exception e) {
    return "";
  }
}
 

Example 38

From project GCM-Demo, under directory /gcm/gcm-client/src/com/google/android/gcm/.

Source file: GCMRegistrar.java

  18 
vote

/** 
 * Gets the application version.
 */
private static int getAppVersion(Context context){
  try {
    PackageInfo packageInfo=context.getPackageManager().getPackageInfo(context.getPackageName(),0);
    return packageInfo.versionCode;
  }
 catch (  NameNotFoundException e) {
    throw new RuntimeException("Coult not get package name: " + e);
  }
}
 

Example 39

From project gddsched2, under directory /trunk/android/src/com/google/android/apps/iosched2/service/.

Source file: SyncService.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 40

From project generic-store-for-android, under directory /src/com/wareninja/opensource/common/.

Source file: WareNinjaUtils.java

  18 
vote

/** 
 * Get current version number.
 * @return
 */
public static String getVersionNumber(Context context){
  String version="?";
  try {
    PackageInfo pi=context.getPackageManager().getPackageInfo(context.getPackageName(),0);
    version=pi.versionName;
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.e(TAG,"Package name not found",e);
  }
  ;
  return version;
}
 

Example 41

From project Gmote, under directory /gmoteclient/src/org/gmote/client/android/.

Source file: GmoteClient.java

  18 
vote

private String getVersionNumber(){
  String version="0.0.0";
  try {
    PackageInfo pi=getPackageManager().getPackageInfo(getPackageName(),0);
    version=pi.versionName;
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.e(DEBUG_TAG,"Package name not found",e);
  }
  if (version.equals("0.0.0")) {
    Log.w(DEBUG_TAG,"Unable to find the app's version number: " + version);
  }
  return version;
}
 

Example 42

From project greenhouse-android, under directory /src/com/springsource/greenhouse/.

Source file: InfoActivity.java

  18 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.info);
  final TextView textViewInfoVersion=(TextView)findViewById(R.id.info_textview_version);
  try {
    ComponentName componentName=new ComponentName(this,AbstractGreenhouseActivity.class);
    String packageName=componentName.getPackageName();
    PackageInfo packageInfo=getPackageManager().getPackageInfo(packageName,0);
    textViewInfoVersion.setText("Version " + packageInfo.versionName);
  }
 catch (  NameNotFoundException e) {
  }
}
 

Example 43

From project Hawksword, under directory /src/com/bw/hawksword/wiktionary/.

Source file: SimpleWikiHelper.java

  18 
vote

/** 
 * Prepare the internal User-Agent string for use. This requires a {@link Context} to pull the package name and version number for thisapplication.
 */
public static void prepareUserAgent(Context context){
  try {
    PackageManager manager=context.getPackageManager();
    PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    sUserAgent=String.format(context.getString(R.string.template_user_agent),info.packageName,info.versionName);
  }
 catch (  NameNotFoundException e) {
    Log.e(TAG,"Couldn't find package information in PackageManager",e);
  }
}
 

Example 44

From project HSR-Timetable, under directory /HSRTimeTable/src/ch/scythe/hsr/helper/.

Source file: AndroidHelper.java

  18 
vote

private static PackageInfo getPackageInfo(PackageManager packageManager,String packageName){
  PackageInfo result=null;
  try {
    result=packageManager.getPackageInfo(packageName,0);
  }
 catch (  NameNotFoundException e) {
  }
  return result;
}
 

Example 45

From project ignition, under directory /ignition-support/ignition-support-lib/src/main/java/com/github/ignition/support/.

Source file: IgnitedDiagnostics.java

  18 
vote

public static String getApplicationVersionString(Context context){
  try {
    PackageManager pm=context.getPackageManager();
    PackageInfo info=pm.getPackageInfo(context.getPackageName(),0);
    return "v" + info.versionName;
  }
 catch (  Exception e) {
    e.printStackTrace();
    return null;
  }
}
 

Example 46

From project iosched, under directory /android/src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 47

From project iosched2011, under directory /android/src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 48

From project iosched_1, under directory /src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 49

From project iosched_2, under directory /android/src/com/google/android/apps/iosched/service/.

Source file: SyncService.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  try {
    final PackageManager manager=context.getPackageManager();
    final PackageInfo info=manager.getPackageInfo(context.getPackageName(),0);
    return info.packageName + "/" + info.versionName+ " ("+ info.versionCode+ ") (gzip)";
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 50

From project iosched_3, under directory /android/src/com/google/android/apps/iosched/sync/.

Source file: SyncHelper.java

  18 
vote

/** 
 * Build and return a user-agent string that can identify this application to remote servers. Contains the package name and version code.
 */
private static String buildUserAgent(Context context){
  String versionName="unknown";
  int versionCode=0;
  try {
    final PackageInfo info=context.getPackageManager().getPackageInfo(context.getPackageName(),0);
    versionName=info.versionName;
    versionCode=info.versionCode;
  }
 catch (  PackageManager.NameNotFoundException ignored) {
  }
  return context.getPackageName() + "/" + versionName+ " ("+ versionCode+ ") (gzip)";
}
 

Example 51

From project jamendo-android, under directory /src/com/teleca/jamendo/.

Source file: JamendoApplication.java

  18 
vote

/** 
 * Retrieves application's version number from the manifest
 * @return
 */
public String getVersion(){
  String version="0.0.0";
  PackageManager packageManager=getPackageManager();
  try {
    PackageInfo packageInfo=packageManager.getPackageInfo(getPackageName(),0);
    version=packageInfo.versionName;
  }
 catch (  NameNotFoundException e) {
    e.printStackTrace();
  }
  return version;
}
 

Example 52

From project k-9, under directory /src/com/fsck/k9/activity/.

Source file: Accounts.java

  18 
vote

/** 
 * Get current version number.
 * @return String version
 */
private String getVersionNumber(){
  String version="?";
  try {
    PackageInfo pi=getPackageManager().getPackageInfo(getPackageName(),0);
    version=pi.versionName;
  }
 catch (  PackageManager.NameNotFoundException e) {
  }
  return version;
}
 

Example 53

From project K6nele, under directory /app/src/ee/ioc/phon/android/speak/.

Source file: Utils.java

  18 
vote

public static String getVersionName(Context c){
  PackageInfo info=getPackageInfo(c);
  if (info == null) {
    return "?.?.?";
  }
  return info.versionName;
}
 

Example 54

From project keepassdroid, under directory /src/com/keepassdroid/.

Source file: AboutDialog.java

  18 
vote

private void setVersion(){
  Context ctx=getContext();
  String version;
  try {
    PackageInfo packageInfo=ctx.getPackageManager().getPackageInfo(ctx.getPackageName(),0);
    version=packageInfo.versionName;
  }
 catch (  NameNotFoundException e) {
    e.printStackTrace();
    version="";
  }
  TextView tv=(TextView)findViewById(R.id.version);
  tv.setText(version);
}
 

Example 55

From project KeyboardTerm, under directory /src/tw/kenshinn/keyboardTerm/.

Source file: ExportKeyboardActivity.java

  18 
vote

private PackageInfo getPackageInfo(){
  PackageManager packageManager=getPackageManager();
  String packageName=getPackageName();
  try {
    PackageInfo info=packageManager.getPackageInfo(packageName,0);
    return info;
  }
 catch (  NameNotFoundException e) {
    return null;
  }
}
 

Example 56

From project lastfm-android, under directory /app/src/fm/last/android/.

Source file: Amazon.java

  18 
vote

public static int getAmazonVersion(Context ctx){
  PackageManager pm=ctx.getPackageManager();
  int result=-1;
  try {
    PackageInfo pi=pm.getPackageInfo("com.amazon.mp3",PackageManager.GET_ACTIVITIES);
    result=pi.versionCode;
  }
 catch (  Exception e) {
    result=-1;
  }
  return result;
}
 

Example 57

From project lightbox-android-webservices, under directory /LightboxAndroidWebServices/src/com/lightbox/android/utils/.

Source file: AndroidUtils.java

  18 
vote

/** 
 * @return the version name of the application
 */
public static String getVersionName(Context context){
  String versionName="unknown version";
  try {
    PackageInfo packageInfo=context.getPackageManager().getPackageInfo(context.getPackageName(),0);
    versionName=packageInfo.versionName;
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.w(TAG,e);
  }
  return versionName;
}
 

Example 58

From project madvertise-android-sdk, under directory /madvertiseSDK/src/de/madvertise/android/sdk/.

Source file: MadvertiseUtil.java

  18 
vote

public static String getApplicationVersion(final Context context){
  String appVersion="";
  PackageManager packageManager=context.getPackageManager();
  try {
    PackageInfo packageInfo=packageManager.getPackageInfo(context.getPackageName(),0);
    appVersion=packageInfo.versionName;
  }
 catch (  NameNotFoundException e) {
    e.printStackTrace();
  }
  return appVersion;
}
 

Example 59

From project MobiPerf, under directory /android/src/com/mobiperf/mobiperf/.

Source file: About.java

  18 
vote

public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.about);
  TextView textView=(TextView)findViewById(R.id.about2);
  textView.setMovementMethod(ScrollingMovementMethod.getInstance());
  TextView version=(TextView)findViewById(R.id.about_version);
  try {
    PackageInfo pInfo=getPackageManager().getPackageInfo(getPackageName(),0);
    version.setText("Version: " + pInfo.versionName);
  }
 catch (  NameNotFoundException e) {
    e.printStackTrace();
  }
}
 

Example 60

From project MWM-for-Android, under directory /src/org/metawatch/manager/.

Source file: Utils.java

  18 
vote

public static String getVersion(Context context){
  try {
    PackageManager packageManager=context.getPackageManager();
    PackageInfo packageInfo=packageManager.getPackageInfo(context.getPackageName(),0);
    return packageInfo.versionName;
  }
 catch (  NameNotFoundException e) {
  }
  return "unknown";
}
 

Example 61

From project MyExpenses, under directory /src/org/totschnig/myexpenses/.

Source file: MyExpenses.java

  18 
vote

/** 
 * @return version number (versionCode)
 */
public int getVersionNumber(){
  int version=-1;
  try {
    PackageInfo pi=getPackageManager().getPackageInfo(getPackageName(),0);
    version=pi.versionCode;
  }
 catch (  Exception e) {
    Log.e("MyExpenses","Package name not found",e);
  }
  return version;
}
 

Example 62

From project npr-android-app, under directory /src/org/npr/android/news/.

Source file: AboutActivity.java

  18 
vote

private String getVersionName(){
  String version="";
  try {
    PackageInfo pi=getPackageManager().getPackageInfo(getPackageName(),0);
    version=pi.versionName;
  }
 catch (  PackageManager.NameNotFoundException e) {
    version="Package name not found";
  }
  return version;
}
 

Example 63

From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/.

Source file: AboutActivity.java

  17 
vote

public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.about);
  TextView versionTextView=(TextView)findViewById(R.id.version);
  TextView buildTimeTextView=(TextView)findViewById(R.id.build_time);
  TextView authorTextView=(TextView)findViewById(R.id.author);
  setTitle("About Amenoid");
  String myPackageName=this.getPackageName();
  int versionCode=0;
  String versionName=null;
  try {
    PackageInfo packageInfo=this.getPackageManager().getPackageInfo(myPackageName,0);
    versionName=packageInfo.versionName;
    versionCode=packageInfo.versionCode;
  }
 catch (  PackageManager.NameNotFoundException e) {
    e.printStackTrace();
  }
  versionTextView.setText("Version: " + versionName + " ("+ versionCode+ ")");
  authorTextView.setText("Author: Dirk Jaeckel <[email protected]>\n");
  final String timestampString=getResources().getString(R.string.buildtimestamp);
  buildTimeTextView.setText("Built: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Long.valueOf(timestampString)));
}
 

Example 64

From project android-api_1, under directory /android-lib/src/com/catchnotes/api/.

Source file: CatchAPI.java

  17 
vote

/** 
 * Constructor.
 * @param appName The name of your application.
 * @param context Android context.
 */
public CatchAPI(String appName,Context context){
  source=appName;
  mContext=context;
  String version="x.xx";
  try {
    PackageInfo info=mContext.getPackageManager().getPackageInfo(mContext.getPackageName(),0);
    version=info.versionName;
  }
 catch (  Exception e) {
  }
  StringBuilder locale=new StringBuilder(5);
  String language=Locale.getDefault().getLanguage();
  if (language != null) {
    locale.append(language);
    String country=Locale.getDefault().getCountry();
    if (country != null) {
      locale.append('-');
      locale.append(country);
    }
  }
  userAgent=appName + '/' + version+ " (Android; "+ Build.VERSION.RELEASE+ "; "+ Build.BRAND+ "; "+ Build.MODEL+ "; "+ locale.toString()+ ')';
  try {
    if (Integer.parseInt(Build.VERSION.SDK) >= Build.VERSION_CODES.ECLAIR_0_1) {
      timestamper=new Time();
    }
  }
 catch (  Exception e) {
  }
}
 

Example 65

From project android-bankdroid, under directory /src/com/liato/bankdroid/.

Source file: AboutActivity.java

  17 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.about);
  PackageInfo pInfo;
  String version="v1.x.x";
  try {
    pInfo=getPackageManager().getPackageInfo(getPackageName(),PackageManager.GET_META_DATA);
    version=pInfo.versionName;
  }
 catch (  final NameNotFoundException e) {
    e.printStackTrace();
  }
  ((TextView)findViewById(R.id.txtVersion)).setText(getText(R.string.version).toString().replace("$version",version));
  this.addTitleButton(R.drawable.title_icon_donate,"donate",this);
  this.addTitleButton(R.drawable.title_icon_web,"web",this);
}
 

Example 66

From project android-joedayz, under directory /Proyectos/FBConnectTest/src/com/facebook/android/.

Source file: Facebook.java

  17 
vote

/** 
 * Query the signature for the application that would be invoked by the given intent and verify that it matches the FB application's signature.
 * @param context
 * @param packageName
 * @return true if the app's signature matches the expected signature.
 */
private boolean validateAppSignatureForPackage(Context context,String packageName){
  PackageInfo packageInfo;
  try {
    packageInfo=context.getPackageManager().getPackageInfo(packageName,PackageManager.GET_SIGNATURES);
  }
 catch (  NameNotFoundException e) {
    return false;
  }
  for (  Signature signature : packageInfo.signatures) {
    if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
      return true;
    }
  }
  return false;
}
 

Example 67

From project android-ocr, under directory /android/src/edu/sfsu/cs/orange/ocr/.

Source file: CaptureActivity.java

  17 
vote

/** 
 * We want the help screen to be shown automatically the first time a new version of the app is run. The easiest way to do this is to check android:versionCode from the manifest, and compare it to a value stored as a preference.
 */
private boolean checkFirstLaunch(){
  try {
    PackageInfo info=getPackageManager().getPackageInfo(getPackageName(),0);
    int currentVersion=info.versionCode;
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
    int lastVersion=prefs.getInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN,0);
    if (lastVersion == 0) {
      isFirstLaunch=true;
    }
 else {
      isFirstLaunch=false;
    }
    if (currentVersion > lastVersion) {
      prefs.edit().putInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN,currentVersion).commit();
      Intent intent=new Intent(this,HelpActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
      String page=lastVersion == 0 ? HelpActivity.DEFAULT_PAGE : HelpActivity.WHATS_NEW_PAGE;
      intent.putExtra(HelpActivity.REQUESTED_PAGE_KEY,page);
      startActivity(intent);
      return true;
    }
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.w(TAG,e);
  }
  return false;
}
 

Example 68

From project Android-Simple-Social-Sharing, under directory /SimpleSocialSharing/src/com/nostra13/socialsharing/facebook/extpack/com/facebook/android/.

Source file: Facebook.java

  17 
vote

/** 
 * Query the signature for the application that would be invoked by the given intent and verify that it matches the FB application's signature.
 * @param activity
 * @param intent
 * @param validSignature
 * @return true if the app's signature matches the expected signature.
 */
private boolean validateAppSignatureForIntent(Activity activity,Intent intent){
  ResolveInfo resolveInfo=activity.getPackageManager().resolveActivity(intent,0);
  if (resolveInfo == null) {
    return false;
  }
  String packageName=resolveInfo.activityInfo.packageName;
  PackageInfo packageInfo;
  try {
    packageInfo=activity.getPackageManager().getPackageInfo(packageName,PackageManager.GET_SIGNATURES);
  }
 catch (  NameNotFoundException e) {
    return false;
  }
  for (  Signature signature : packageInfo.signatures) {
    if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
      return true;
    }
  }
  return false;
}
 

Example 69

From project android-thaiime, under directory /latinime/src/com/sugree/inputmethod/latin/.

Source file: DebugSettings.java

  17 
vote

private void updateDebugMode(){
  if (mDebugMode == null) {
    return;
  }
  boolean isDebugMode=mDebugMode.isChecked();
  String version="";
  try {
    PackageInfo info=getPackageManager().getPackageInfo(getPackageName(),0);
    version="Version " + info.versionName;
  }
 catch (  NameNotFoundException e) {
    Log.e(TAG,"Could not find version info.");
  }
  if (!isDebugMode) {
    mDebugMode.setTitle(version);
    mDebugMode.setSummary("");
  }
 else {
    mDebugMode.setTitle(getResources().getString(R.string.prefs_debug_mode));
    mDebugMode.setSummary(version);
  }
}
 

Example 70

From project AndroidCommon, under directory /src/com/asksven/android/system/.

Source file: Installation.java

  17 
vote

public static boolean isInstalledOnSdCard(Context context){
  if (VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) {
    PackageManager pm=context.getPackageManager();
    try {
      PackageInfo pi=pm.getPackageInfo(context.getPackageName(),0);
      ApplicationInfo ai=pi.applicationInfo;
      return (ai.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == ApplicationInfo.FLAG_EXTERNAL_STORAGE;
    }
 catch (    NameNotFoundException e) {
    }
  }
  try {
    String filesDir=context.getFilesDir().getAbsolutePath();
    if (filesDir.startsWith("/data/")) {
      return false;
    }
 else     if (filesDir.contains("/mnt/") || filesDir.contains("/sdcard/")) {
      return true;
    }
  }
 catch (  Throwable e) {
  }
  return false;
}
 

Example 71

From project androidquery, under directory /auth/com/androidquery/auth/.

Source file: FacebookHandle.java

  17 
vote

private boolean validateAppSignatureForIntent(Context context,Intent intent){
  PackageManager pm=context.getPackageManager();
  ResolveInfo resolveInfo=pm.resolveActivity(intent,0);
  if (resolveInfo == null) {
    return false;
  }
  String packageName=resolveInfo.activityInfo.packageName;
  PackageInfo packageInfo;
  try {
    packageInfo=pm.getPackageInfo(packageName,PackageManager.GET_SIGNATURES);
  }
 catch (  NameNotFoundException e) {
    return false;
  }
  for (  Signature signature : packageInfo.signatures) {
    if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
      return true;
    }
  }
  return false;
}
 

Example 72

From project androidTileMapEditor_1, under directory /src/it/sineo/android/tileMapEditor/.

Source file: AboutActivity.java

  17 
vote

public View createTabContent(String tag,LayoutInflater inflater){
  Context ctx=inflater.getContext();
  if (TAG_INFO.equals(tag)) {
    View v=inflater.inflate(R.layout.about_info,null,false);
    String version="?";
    try {
      PackageInfo info=ctx.getPackageManager().getPackageInfo(ctx.getPackageName(),0);
      version=info.versionName;
    }
 catch (    PackageManager.NameNotFoundException pmnnfex) {
      pmnnfex.printStackTrace();
    }
    ((TextView)v.findViewById(R.id.about_info_version)).setText(getResources().getString(R.string.about_info_version,version));
    ImageView ivDonate=(ImageView)v.findViewById(R.id.donate_button);
    ivDonate.setOnClickListener(new View.OnClickListener(){
      @Override public void onClick(      View v){
        Intent i=new Intent(Intent.ACTION_VIEW,Uri.parse(getString(R.string.paypal_donate_url)));
        startActivity(i);
      }
    }
);
    return v;
  }
 else   if (TAG_CHANGELOG.equals(tag)) {
    return ChangelogFactory.inflate(ctx,R.xml.changelog);
  }
 else   if (TAG_LICENSE.equals(tag)) {
    return createLicenseView(R.raw.license,inflater);
  }
  Log.e(getClass().getName(),"unknown tag: " + tag);
  return null;
}
 

Example 73

From project android_7, under directory /src/org/immopoly/android/fragments/.

Source file: MapFragment.java

  17 
vote

private void showSplashScreen(){
  mSplashscreen.setVisibility(View.VISIBLE);
  PackageInfo packInfo;
  String version="";
  try {
    packInfo=getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(),0);
    version="Version " + packInfo.versionName + " ("+ packInfo.versionCode+ ")";
  }
 catch (  NameNotFoundException e) {
    e.printStackTrace();
  }
  ((TextView)mSplashscreen.findViewById(R.id.splash_version)).setText(version);
  new Handler().postDelayed(new Runnable(){
    public void run(){
      hideSplashScreen();
    }
  }
,10000);
}
 

Example 74

From project android_packages_apps_Nfc, under directory /src/com/android/nfc/.

Source file: NfceeAccessControl.java

  17 
vote

/** 
 * Check with package manager if the pkg may use NFCEE. Does not use cache.
 */
boolean checkPackageNfceeAccess(String pkg){
  PackageManager pm=mContext.getPackageManager();
  try {
    PackageInfo info=pm.getPackageInfo(pkg,PackageManager.GET_SIGNATURES);
    if (info.signatures == null) {
      return false;
    }
    for (    Signature s : info.signatures) {
      if (s == null) {
        continue;
      }
      String[] packages=mNfceeAccess.get(s);
      if (packages == null) {
        continue;
      }
      if (packages.length == 0) {
        if (DBG)         Log.d(TAG,"Granted NFCEE access to " + pkg + " (wildcard)");
        return true;
      }
      for (      String p : packages) {
        if (pkg.equals(p)) {
          if (DBG)           Log.d(TAG,"Granted access to " + pkg + " (explicit)");
          return true;
        }
      }
    }
    if (mDebugPrintSignature) {
      Log.w(TAG,"denied NFCEE access for " + pkg + " with signature:");
      for (      Signature s : info.signatures) {
        if (s != null) {
          Log.w(TAG,s.toCharsString());
        }
      }
    }
  }
 catch (  NameNotFoundException e) {
  }
  return false;
}
 

Example 75

From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/latin/.

Source file: DebugSettings.java

  17 
vote

private void updateDebugMode(){
  if (mDebugMode == null) {
    return;
  }
  boolean isDebugMode=mDebugMode.isChecked();
  String version="";
  try {
    PackageInfo info=getPackageManager().getPackageInfo(getPackageName(),0);
    version="Version " + info.versionName;
  }
 catch (  NameNotFoundException e) {
    Log.e(TAG,"Could not find version info.");
  }
  if (!isDebugMode) {
    mDebugMode.setTitle(version);
    mDebugMode.setSummary("");
  }
 else {
    mDebugMode.setTitle(getResources().getString(R.string.prefs_debug_mode));
    mDebugMode.setSummary(version);
  }
}
 

Example 76

From project BazaarUtils, under directory /src/com/congenialmobile/utils/.

Source file: WhatsNewActivity.java

  17 
vote

/** 
 * @param activity
 * @param forceShow boolean to force show even if there wan no old version found on the device
 * @param app_icon
 * @param stringIds
 * @return true if the dialog is called to be shown
 */
public static boolean showWhatsNewIfNeeded(Activity activity,boolean forceShow,int app_icon,int... stringIds){
  PackageInfo info;
  String packageName=activity.getPackageName();
  int versionCode=0;
  try {
    info=activity.getPackageManager().getPackageInfo(packageName,0);
    if (info != null) {
      versionCode=info.versionCode;
    }
  }
 catch (  NameNotFoundException e) {
    Log.e("WhatsNew","",e);
  }
  SharedPreferences settings=activity.getSharedPreferences(PREFS_NAME,0);
  int oldVersionCode=settings.getInt(PREFS_VERSION_CODE,-1);
  SharedPreferences.Editor editor=settings.edit();
  editor.putInt(PREFS_VERSION_CODE,versionCode);
  editor.commit();
  if (((oldVersionCode == -1) && !(forceShow)) || (oldVersionCode == versionCode)) {
    return false;
  }
  Intent i=new Intent(activity,WhatsNewActivity.class);
  i.putExtra(WhatsNewActivity.EXTRA_NOTE_STRINGS,stringIds);
  i.putExtra(WhatsNewActivity.EXTRA_ICON_DRAWABLE,app_icon);
  activity.startActivity(i);
  return true;
}
 

Example 77

From project Birthdays, under directory /src/com/rexmenpara/birthdays/.

Source file: BirthdaysActivity.java

  17 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  ContextManager.setContext(this);
  StartupService startupService=new StartupService();
  startupService.onStartupApplication(this);
  super.onCreate(savedInstanceState);
  db=DBAdapter.getInstance();
  SharedPreferences pref=getSharedPreferences(Constants.TAG,Context.MODE_PRIVATE);
  int versionCode=pref.getInt("versionCode",-1);
  PackageInfo pInfo=null;
  try {
    pInfo=getPackageManager().getPackageInfo(Constants.PACKAGE,PackageManager.GET_META_DATA);
  }
 catch (  NameNotFoundException e) {
    Log.e(Constants.TAG,"Application is not properly installed",e);
  }
  int localVersionCode=pInfo.versionCode;
  if (versionCode == -1) {
    showFirstExecDialog("Thank you for installing Birthdays!\n\nDo you want to load all the birthdays now?",pref,localVersionCode);
  }
 else   if (versionCode != localVersionCode) {
    showFirstExecDialog("Thank you for updating Birthdays!\n\nIt is recommended that you sync your contacts again.",pref,localVersionCode);
  }
 else {
    loadData();
  }
}
 

Example 78

From project Bitcoin-Wallet-for-Android, under directory /wallet/src/de/schildbach/wallet/util/.

Source file: ErrorReporter.java

  17 
vote

private static void appendReport(final StringBuilder report,final Context context){
  try {
    final PackageManager pm=context.getPackageManager();
    final PackageInfo pi=pm.getPackageInfo(context.getPackageName(),0);
    final Resources res=context.getResources();
    final Configuration config=res.getConfiguration();
    final ActivityManager activityManager=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
    report.append("Date: " + new Date() + "\n");
    report.append("Version: " + pi.versionName + " ("+ pi.versionCode+ ")\n");
    report.append("Package: " + pi.packageName + "\n");
    report.append("Phone Model: " + android.os.Build.MODEL + "\n");
    report.append("Android Version: " + android.os.Build.VERSION.RELEASE + "\n");
    report.append("Board: " + android.os.Build.BOARD + "\n");
    report.append("Brand: " + android.os.Build.BRAND + "\n");
    report.append("Device: " + android.os.Build.DEVICE + "\n");
    report.append("Display: " + android.os.Build.DISPLAY + "\n");
    report.append("Finger Print: " + android.os.Build.FINGERPRINT + "\n");
    report.append("Host: " + android.os.Build.HOST + "\n");
    report.append("ID: " + android.os.Build.ID + "\n");
    report.append("Model: " + android.os.Build.MODEL + "\n");
    report.append("Product: " + android.os.Build.PRODUCT + "\n");
    report.append("Tags: " + android.os.Build.TAGS + "\n");
    report.append("Time: " + android.os.Build.TIME + "\n");
    report.append("Type: " + android.os.Build.TYPE + "\n");
    report.append("User: " + android.os.Build.USER + "\n");
    report.append("Configuration: " + config + "\n");
    report.append("Screen Layout: size " + (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) + " long "+ (config.screenLayout & Configuration.SCREENLAYOUT_LONG_MASK)+ "\n");
    report.append("Display Metrics: " + res.getDisplayMetrics() + "\n");
    report.append("Memory Class: " + activityManager.getMemoryClass() + "\n");
    report.append("Databases:");
    for (    final String db : context.databaseList())     report.append(" " + db);
    report.append("\n\n\n");
  }
 catch (  NameNotFoundException e) {
    e.printStackTrace();
  }
}
 

Example 79

From project BSPAN---Bluetooth-Sensor-Processing-for-Android, under directory /AndroidBTService/src/com/t2/biofeedback/activity/.

Source file: BTServiceManager.java

  17 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  this.setContentView(R.layout.manager);
  this.findViewById(R.id.bluetoothSettingsButton).setOnClickListener(this);
  this.findViewById(R.id.about).setOnClickListener(this);
  this.deviceManager=DeviceManager.getInstanceNoCreate();
  if (this.deviceManager == null) {
    Log.e(TAG,"There is no device manager instance!");
    return;
  }
  this.deviceList=(ListView)this.findViewById(R.id.list);
  this.deviceListAdapter=new ManagerItemAdapter(this,this.deviceManager,R.layout.manager_item);
  this.deviceList.setAdapter(this.deviceListAdapter);
  this.generalBroadcastReceiver=new GeneralReceiver();
  IntentFilter filter=new IntentFilter();
  filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
  filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
  filter.addAction(BioFeedbackService.ACTION_STATUS_BROADCAST);
  this.registerReceiver(this.generalBroadcastReceiver,filter);
  this.bluetoothDisabledDialog=new AlertDialog.Builder(this).setMessage("Bluetooth is not enabled.").setOnCancelListener(new OnCancelListener(){
    @Override public void onCancel(    DialogInterface dialog){
      finish();
    }
  }
).setPositiveButton("Setup Bluetooth",new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int which){
      startBluetoothSettings();
    }
  }
).create();
  try {
    PackageManager packageManager=this.getPackageManager();
    PackageInfo info=packageManager.getPackageInfo(this.getPackageName(),0);
    mVersionName=info.versionName;
    Log.i(TAG,"Spine server Test Application Version " + mVersionName);
  }
 catch (  NameNotFoundException e) {
    Log.e(TAG,e.toString());
  }
}
 

Example 80

From project CHMI, under directory /src/org/kaldax/lib/net/app/netresource/.

Source file: ActualInfo.java

  17 
vote

public ActualInfo(Activity activity,Handler msgHandler,String strAppName,String strLocale){
  this.activity=activity;
  this.strAppName=strAppName;
  thread=null;
  if (strLocale.compareTo("") == 0) {
    strLocale="en";
  }
  this.strLocale=strLocale;
  this.msgHandler=msgHandler;
  this.bCheckTitleNews=true;
  bForceReloadTitle=false;
  PackageManager manager=activity.getPackageManager();
  PackageInfo info;
  try {
    info=manager.getPackageInfo(activity.getPackageName(),0);
    this.packageName=info.packageName;
    this.versionCode=info.versionCode;
    this.versionName=info.versionName;
    setTitle(this.packageName + " v." + this.versionName);
  }
 catch (  NameNotFoundException ex) {
    Logger.getLogger(ActualInfo.class.getName()).log(Level.SEVERE,null,ex);
  }
}
 

Example 81

From project cicada, under directory /cicada/src/org/cicadasong/cicada/.

Source file: PackageUtil.java

  17 
vote

public static List<AppDescription> getCicadaAppsFromPackage(PackageManager pm,String packageName){
  ArrayList<AppDescription> apps=new ArrayList<AppDescription>();
  try {
    PackageInfo pi=pm.getPackageInfo(packageName,PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);
    if (pi == null || pi.services == null) {
      return apps;
    }
    for (    ServiceInfo serviceInfo : pi.services) {
      Bundle metadata=serviceInfo.metaData;
      if (metadata != null) {
        String appTypeString=serviceInfo.metaData.getString(APP_TYPE_METADATA_KEY);
        if (appTypeString != null) {
          if (!serviceInfo.exported) {
            Log.w(Cicada.TAG,"Found service \"" + serviceInfo.name + "\", but it doesn't have"+ " android:exported=\"true\" in its definition, so Cicada can't use it.");
          }
 else {
            AppType mode=AppType.APP;
            try {
              mode=AppType.valueOf(appTypeString);
            }
 catch (            Exception e) {
              Log.w(Cicada.TAG,"Couldn't recognize app type \"" + appTypeString + "\" for "+ "service \""+ serviceInfo.name+ "\", assuming "+ mode.name());
            }
            AppDescription app=new AppDescription(packageName,serviceInfo.name,null,serviceInfo.loadLabel(pm).toString(),mode);
            apps.add(app);
          }
        }
      }
    }
  }
 catch (  NameNotFoundException e) {
    Log.w(Cicada.TAG,"PackageManager couldn't find package named: " + packageName);
  }
  return apps;
}
 

Example 82

From project CineShowTime-Android, under directory /Libraries/CineShowTime/src/com/binomed/showtime/android/util/activity/.

Source file: AbstractCineShowTimeActivity.java

  17 
vote

@Override public void onQuickActionClicked(QuickActionWidget widget,int position){
  final int MENU_PREF=0;
  final int MENU_ABOUT=1;
  final int MENU_HELP=2;
  if (position == MENU_PREF) {
    tracker.trackEvent(CineShowtimeCst.ANALYTICS_CATEGORY_ACTIVITY,CineShowtimeCst.ANALYTICS_ACTION_OPEN,CineShowtimeCst.ANALYTICS_LABEL_PREFERENCE,0);
    Intent launchPreferencesIntent=new Intent().setClass(getApplicationContext(),CineShowTimePreferencesActivity.class);
    startActivityForResult(launchPreferencesIntent,CineShowtimeCst.ACTIVITY_RESULT_PREFERENCES);
  }
 else   if (position == MENU_ABOUT) {
    tracker.trackEvent(CineShowtimeCst.ANALYTICS_CATEGORY_ACTIVITY,CineShowtimeCst.ANALYTICS_ACTION_OPEN,CineShowtimeCst.ANALYTICS_LABEL_ABOUT,0);
    AlertDialog.Builder aboutDialog=new AlertDialog.Builder(AbstractCineShowTimeActivity.this);
    try {
      PackageInfo pi=getPackageManager().getPackageInfo(getPackageName(),0);
      aboutDialog.setTitle(Html.fromHtml(new StringBuilder().append("CineShowTime ").append(pi.versionName).append("<br>").toString()));
    }
 catch (    Exception e) {
    }
    aboutDialog.setCancelable(false);
    aboutDialog.setIcon(R.drawable.icon);
    aboutDialog.setNeutralButton(R.string.btnClose,null);
    AboutView aboutView=new AboutView(AbstractCineShowTimeActivity.this);
    aboutDialog.setView(aboutView);
    aboutDialog.show();
  }
 else   if (position == MENU_HELP) {
    tracker.trackEvent(CineShowtimeCst.ANALYTICS_CATEGORY_ACTIVITY,CineShowtimeCst.ANALYTICS_ACTION_OPEN,CineShowtimeCst.ANALYTICS_LABEL_HELP,0);
    Intent launchPreferencesIntent=IntentShowtime.createHelpAndShowTime(getApplicationContext());
    startActivityForResult(launchPreferencesIntent,0);
  }
}
 

Example 83

From project cornerstone, under directory /frameworks/base/services/java/com/android/server/am/.

Source file: ActivityManagerService.java

  17 
vote

/** 
 * Utility function for addErrorToDropBox and handleStrictModeViolation's logging to append various headers to the dropbox log text.
 */
private void appendDropBoxProcessHeaders(ProcessRecord process,String processName,StringBuilder sb){
  if (process == null) {
    sb.append("Process: ").append(processName).append("\n");
    return;
  }
synchronized (this) {
    sb.append("Process: ").append(processName).append("\n");
    int flags=process.info.flags;
    IPackageManager pm=AppGlobals.getPackageManager();
    sb.append("Flags: 0x").append(Integer.toString(flags,16)).append("\n");
    for (    String pkg : process.pkgList) {
      sb.append("Package: ").append(pkg);
      try {
        PackageInfo pi=pm.getPackageInfo(pkg,0);
        if (pi != null) {
          sb.append(" v").append(pi.versionCode);
          if (pi.versionName != null) {
            sb.append(" (").append(pi.versionName).append(")");
          }
        }
      }
 catch (      RemoteException e) {
        Slog.e(TAG,"Error getting package info: " + pkg,e);
      }
      sb.append("\n");
    }
  }
}
 

Example 84

From project danbooru-gallery-android, under directory /src/tw/idv/palatis/danboorugallery/.

Source file: DanbooruGalleryPreferenceActivity.java

  17 
vote

@Override protected void onStart(){
  if (preferences.contains("json_hosts"))   try {
    hosts=D.HostsFromJSONArray(new JSONArray(preferences.getString("json_hosts","")));
  }
 catch (  JSONException ex) {
    D.Log.wtf(ex);
  }
 else   hosts=new ArrayList<Host>();
  try {
    PackageInfo manager=getPackageManager().getPackageInfo(getPackageName(),0);
    findPreference("preferences_about_version").setSummary(manager.versionName);
  }
 catch (  NameNotFoundException e) {
  }
  ListPreference pref_hosts=(ListPreference)findPreference("preferences_hosts_select");
  pref_hosts.setOnPreferenceChangeListener(new OnPreferenceChangeListener(){
    @Override public boolean onPreferenceChange(    Preference preference,    Object newValue){
      String name=hosts.get(Integer.parseInt((String)newValue)).name;
      preference.setSummary(String.format(getString(R.string.preferences_hosts_selected_host),name));
      return true;
    }
  }
);
  CheckBoxPreference pref_aggressive=(CheckBoxPreference)findPreference("preferences_options_aggressive_prefetch");
  pref_aggressive.setChecked(preferences.getBoolean("aggressive_prefetch",false));
  CheckBoxPreference pref_hqimage=(CheckBoxPreference)findPreference("preferences_options_high_quality_image");
  pref_hqimage.setChecked(preferences.getBoolean("high_quality_image",false));
  notifyHostsChanged();
  super.onStart();
}
 

Example 85

From project DrmLicenseService, under directory /src/com/sonyericsson/android/drm/drmlicenseservice/.

Source file: HttpClient.java

  17 
vote

private String getUserAgent(){
  String userAgent=Constants.FALLBACK_USER_AGENT;
  boolean uaFinalized=false;
  if (mParameters != null && mParameters.containsKey(Constants.DRM_KEYPARAM_USER_AGENT)) {
    String tempUA=mParameters.getString(Constants.DRM_KEYPARAM_USER_AGENT);
    if (tempUA != null && tempUA.length() > 0) {
      userAgent=tempUA;
      uaFinalized=true;
    }
  }
  if (!uaFinalized) {
    String versionName=null;
    CharSequence appName=null;
    try {
      PackageManager packageManager=mContext.getPackageManager();
      PackageInfo pInfo=packageManager.getPackageInfo(mContext.getPackageName(),0);
      versionName=pInfo.versionName;
      ApplicationInfo applicationInfo=pInfo.applicationInfo;
      appName=packageManager.getApplicationLabel(applicationInfo);
    }
 catch (    NameNotFoundException e) {
    }
    if (versionName != null && appName != null) {
      userAgent=appName + "/" + versionName+ " ("+ Build.VERSION.RELEASE+ ")";
    }
  }
  return userAgent;
}
 

Example 86

From project droid-comic-viewer, under directory /src/net/robotmedia/acv/ui/settings/mobile/.

Source file: AboutSettingsActivity.java

  17 
vote

@Override protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  Preference version=findPreference(Constants.VERSION_KEY);
  String versionName;
  try {
    PackageInfo info=getPackageManager().getPackageInfo(this.getPackageName(),0);
    versionName=info.versionName;
  }
 catch (  NameNotFoundException e) {
    e.printStackTrace();
    versionName="1";
  }
  version.setSummary(version.getSummary() + versionName);
  final Preference subscribe=findPreference(KEY_SUBSCRIBE);
  subscribe.setOnPreferenceClickListener(new OnPreferenceClickListener(){
    public boolean onPreferenceClick(    Preference preference){
      Intent myIntent=new Intent(AboutSettingsActivity.this,SubscribeActivity.class);
      myIntent.putExtra(SubscribeActivity.SOURCE_EXTRA,SOURCE_VALUE);
      startActivityForResult(myIntent,Constants.SUBSCRIBE_CODE);
      return true;
    }
  }
);
}
 

Example 87

From project droidgiro-android, under directory /src/se/droidgiro/.

Source file: About.java

  17 
vote

protected void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.about);
  TextView versionTextView=(TextView)findViewById(R.id.about_version);
  try {
    PackageInfo packageInfo=getPackageManager().getPackageInfo(getPackageName(),0);
    versionTextView.setText(getString(R.string.about_version) + " " + packageInfo.versionName);
  }
 catch (  NameNotFoundException e) {
    new AlertDialog.Builder(this).setMessage("error: " + e).show();
  }
  TextView serverLinkTextView=(TextView)findViewById(R.id.about_link);
  final String serverLinkText=serverLinkTextView.getText().toString();
  SpannableString str=SpannableString.valueOf(serverLinkTextView.getText());
  Linkify.addLinks(str,Linkify.ALL);
  serverLinkTextView.setText(str);
  serverLinkTextView.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      Intent myIntent=new Intent(Intent.ACTION_VIEW,Uri.parse(serverLinkText));
      startActivity(myIntent);
    }
  }
);
}
 

Example 88

From project droidkit, under directory /src/org/droidkit/app/.

Source file: UpdateService.java

  17 
vote

private void parseJSONResponse(String obj){
  int currentVersion=0;
  try {
    PackageInfo info=getPackageManager().getPackageInfo(getPackageName(),0);
    currentVersion=info.versionCode;
  }
 catch (  NameNotFoundException e) {
    Log.e("DroidKit","Wtf! How can we not find ourselves! " + e.toString());
  }
  try {
    JSONObject json=new JSONObject(obj);
    JSONArray arr=json.getJSONArray("updates");
    JSONObject update=arr.getJSONObject(0);
    int updateVersion=update.getInt("version.code");
    Log.i("DroidKit","Latest verion: " + updateVersion);
    if (currentVersion < updateVersion) {
      boolean download=mPreferences.getBoolean("download.updates",true);
      if (download) {
        notifyDownloading(obj);
        isDownloading=true;
        boolean result=updateVersion(update.getString("apk.url"));
        mNotificationManager.cancel("Downloading update...",UPDATE_DOWNLOADING_ID);
        isDownloading=false;
        Message.obtain(mHandler,DOWNLOAD_DONE,null).sendToTarget();
        if (result) {
          notifyUser(obj);
        }
      }
 else {
        notifyUser(obj);
      }
    }
  }
 catch (  JSONException e) {
    Log.e("DroidKit","Error parsing update server response: " + e.toString());
  }
  stopSelf();
}
 

Example 89

From project dungbeetle, under directory /src/com/facebook/android/.

Source file: Facebook.java

  17 
vote

/** 
 * Query the signature for the application that would be invoked by the given intent and verify that it matches the FB application's signature.
 * @param activity
 * @param intent
 * @param validSignature
 * @return true if the app's signature matches the expected signature.
 */
private boolean validateAppSignatureForIntent(Activity activity,Intent intent){
  ResolveInfo resolveInfo=activity.getPackageManager().resolveActivity(intent,0);
  if (resolveInfo == null) {
    return false;
  }
  String packageName=resolveInfo.activityInfo.packageName;
  PackageInfo packageInfo;
  try {
    packageInfo=activity.getPackageManager().getPackageInfo(packageName,PackageManager.GET_SIGNATURES);
  }
 catch (  NameNotFoundException e) {
    return false;
  }
  for (  Signature signature : packageInfo.signatures) {
    if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
      return true;
    }
  }
  return false;
}
 

Example 90

From project Ebento, under directory /src/mobisocial/bento/ebento/util/.

Source file: InitialHelper.java

  17 
vote

public Musubi initMusubiInstance(boolean bAsync){
  boolean bInstalled=false;
  try {
    bInstalled=Musubi.isMusubiInstalled(mActivity);
  }
 catch (  Exception e) {
    bInstalled=false;
  }
  if (!bInstalled) {
    goMusubiOnMarket();
    return null;
  }
  Intent intent=mActivity.getIntent();
  Musubi musubi=Musubi.forIntent(mActivity,intent);
  if (musubi == null) {
    goMarket();
    mActivity.finish();
    return null;
  }
  EventManager manager=EventManager.getInstance();
  manager.init(musubi);
  manager.setFromMusubi(Musubi.isMusubiIntent(intent));
  int versionCode=0;
  try {
    PackageInfo packageInfo=mActivity.getPackageManager().getPackageInfo("mobisocial.bento.ebento",PackageManager.GET_META_DATA);
    versionCode=packageInfo.versionCode;
  }
 catch (  NameNotFoundException e) {
    e.printStackTrace();
  }
  if (bAsync) {
    new EventAsyncTask(musubi,mActivity,versionCode).execute();
  }
 else {
    manager.setMusubi(musubi,versionCode);
  }
  return musubi;
}
 

Example 91

From project evodroid, under directory /src/com/sonorth/evodroid/.

Source file: About.java

  17 
vote

public void onCreate(Bundle icicle){
  super.onCreate(icicle);
  setContentView(R.layout.about);
  if (BlackBerryUtils.getInstance().isBlackBerry()) {
    TextView appTitle=(TextView)findViewById(R.id.about_first_line);
    appTitle.setText(getResources().getText(R.string.app_title_blackberry));
  }
  TextView version=(TextView)findViewById(R.id.about_version);
  PackageManager pm=getPackageManager();
  try {
    PackageInfo pi=pm.getPackageInfo("com.sonorth.evodroid",0);
    version.setText(getResources().getText(R.string.version) + " " + pi.versionName);
  }
 catch (  NameNotFoundException e) {
  }
  Button tos=(Button)findViewById(R.id.about_tos);
  tos.setOnClickListener(new View.OnClickListener(){
    public void onClick(    View v){
      Uri uri=Uri.parse(app_author_url + tos_url);
      startActivity(new Intent(Intent.ACTION_VIEW,uri));
    }
  }
);
  Button pp=(Button)findViewById(R.id.about_privacy);
  pp.setOnClickListener(new View.OnClickListener(){
    public void onClick(    View v){
      Uri uri=Uri.parse(app_author_url + privacy_policy_url);
      startActivity(new Intent(Intent.ACTION_VIEW,uri));
    }
  }
);
}
 

Example 92

From project facebook-android-sdk, under directory /facebook/src/com/facebook/android/.

Source file: Facebook.java

  17 
vote

/** 
 * Query the signature for the application that would be invoked by the given intent and verify that it matches the FB application's signature.
 * @param context
 * @param packageName
 * @return true if the app's signature matches the expected signature.
 */
private boolean validateAppSignatureForPackage(Context context,String packageName){
  PackageInfo packageInfo;
  try {
    packageInfo=context.getPackageManager().getPackageInfo(packageName,PackageManager.GET_SIGNATURES);
  }
 catch (  NameNotFoundException e) {
    return false;
  }
  for (  Signature signature : packageInfo.signatures) {
    if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
      return true;
    }
  }
  return false;
}
 

Example 93

From project FileExplorer, under directory /src/net/micode/fileexplorer/.

Source file: Util.java

  17 
vote

public static Drawable getApkIcon(Context context,String apkPath){
  PackageManager pm=context.getPackageManager();
  PackageInfo info=pm.getPackageArchiveInfo(apkPath,PackageManager.GET_ACTIVITIES);
  if (info != null) {
    ApplicationInfo appInfo=info.applicationInfo;
    appInfo.sourceDir=apkPath;
    appInfo.publicSourceDir=apkPath;
    try {
      return appInfo.loadIcon(pm);
    }
 catch (    OutOfMemoryError e) {
      Log.e(LOG_TAG,e.toString());
    }
  }
  return null;
}
 

Example 94

From project Gaggle, under directory /src/com/geeksville/location/.

Source file: LeonardoLiveWriter.java

  17 
vote

/** 
 * Constructor
 * @param serverURL The server we are using, www.livetrack24.com/track.php for real server, test.livetrack24.com for test
 * @param userName The user login name on the site (low security)
 * @param password The user password
 * @throws Exception
 */
public LeonardoLiveWriter(Context context,String serverURL,String userName,String password,String vehicleName,int vehicleType,int expectedInterval) throws Exception {
  PackageManager pm=context.getPackageManager();
  PackageInfo pi;
  try {
    pi=pm.getPackageInfo(context.getPackageName(),0);
    ourVersion=pi.versionName;
  }
 catch (  NameNotFoundException eNnf) {
    throw new RuntimeException(eNnf);
  }
  URL url=new URL(serverURL + "/track.php");
  trackURL=url.toString();
  url=new URL(serverURL + "/client.php");
  clientURL=url.toString();
  this.userName=userName;
  this.password=password;
  this.vehicleType=vehicleType;
  this.vehicleName=vehicleName;
  expectedIntervalSecs=expectedInterval;
  doLogin();
}
 

Example 95

From project gh4a, under directory /src/com/gh4a/.

Source file: BaseActivity.java

  17 
vote

public void openAboutDialog(){
  Dialog dialog=new Dialog(this);
  dialog.setContentView(R.layout.about_dialog);
  try {
    PackageInfo packageInfo=getPackageManager().getPackageInfo(getPackageName(),0);
    String versionName=packageInfo.versionName;
    dialog.setTitle(getResources().getString(R.string.app_name) + " v" + versionName);
  }
 catch (  PackageManager.NameNotFoundException e) {
    dialog.setTitle(getResources().getString(R.string.app_name));
  }
  Button btnByEmail=(Button)dialog.findViewById(R.id.btn_by_email);
  btnByEmail.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View arg0){
      Intent sendIntent=new Intent(Intent.ACTION_SEND);
      sendIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{getResources().getString(R.string.my_email)});
      sendIntent.setType("message/rfc822");
      startActivity(Intent.createChooser(sendIntent,"Select email application."));
    }
  }
);
  Button btnByGh4a=(Button)dialog.findViewById(R.id.btn_by_gh4a);
  btnByGh4a.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View arg0){
      if (isAuthorized()) {
        Intent intent=new Intent().setClass(BaseActivity.this,IssueCreateActivity.class);
        intent.putExtra(Constants.Repository.REPO_OWNER,getResources().getString(R.string.my_username));
        intent.putExtra(Constants.Repository.REPO_NAME,getResources().getString(R.string.my_repo));
        startActivity(intent);
      }
 else {
        showMessage("Please login",false);
      }
    }
  }
);
  dialog.show();
}
 

Example 96

From project Gingerbread-Keyboard, under directory /src/com/android/inputmethod/latin/.

Source file: LatinIMEDebugSettings.java

  17 
vote

private void updateDebugMode(){
  if (mDebugMode == null) {
    return;
  }
  boolean isDebugMode=mDebugMode.isChecked();
  String version="";
  try {
    PackageInfo info=getPackageManager().getPackageInfo(getPackageName(),0);
    version="Version " + info.versionName;
  }
 catch (  NameNotFoundException e) {
    Log.e(TAG,"Could not find version info.");
  }
  if (!isDebugMode) {
    mDebugMode.setTitle(version);
    mDebugMode.setSummary("");
  }
 else {
    mDebugMode.setTitle(getResources().getString(R.string.prefs_debug_mode));
    mDebugMode.setSummary(version);
  }
}
 

Example 97

From project HarleyDroid, under directory /src/org/harleydroid/.

Source file: About.java

  17 
vote

static void about(final Activity activity){
  LayoutInflater li=LayoutInflater.from(activity);
  View view=li.inflate(R.layout.about,null);
  AlertDialog.Builder builder=new AlertDialog.Builder(activity);
  builder.setView(view);
  builder.setPositiveButton(R.string.about_ok,null);
  builder.setNeutralButton(R.string.about_license,new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int which){
      Eula.show(activity,true);
    }
  }
);
  builder.setIcon(R.drawable.ic_launcher_harleydroid);
  AlertDialog dialog=builder.create();
  dialog.show();
  try {
    PackageInfo pi=activity.getPackageManager().getPackageInfo("org.harleydroid",PackageManager.GET_META_DATA);
    ((TextView)dialog.findViewById(R.id.about_version)).setText(pi.versionName);
  }
 catch (  NameNotFoundException e) {
  }
}
 

Example 98

From project huiswerk, under directory /print/zxing-1.6/android/src/com/google/zxing/client/android/.

Source file: CaptureActivity.java

  17 
vote

/** 
 * We want the help screen to be shown automatically the first time a new version of the app is run. The easiest way to do this is to check android:versionCode from the manifest, and compare it to a value stored as a preference.
 */
private boolean showHelpOnFirstLaunch(){
  try {
    PackageInfo info=getPackageManager().getPackageInfo(PACKAGE_NAME,0);
    int currentVersion=info.versionCode;
    this.versionName=info.versionName;
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
    int lastVersion=prefs.getInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN,0);
    if (currentVersion > lastVersion) {
      prefs.edit().putInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN,currentVersion).commit();
      Intent intent=new Intent(this,HelpActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
      String page=(lastVersion == 0) ? HelpActivity.DEFAULT_PAGE : HelpActivity.WHATS_NEW_PAGE;
      intent.putExtra(HelpActivity.REQUESTED_PAGE_KEY,page);
      startActivity(intent);
      return true;
    }
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.w(TAG,e);
  }
  return false;
}
 

Example 99

From project ICS_LatinIME_QHD, under directory /java/src/com/android/inputmethod/latin/.

Source file: DebugSettings.java

  17 
vote

private void updateDebugMode(){
  if (mDebugMode == null) {
    return;
  }
  boolean isDebugMode=mDebugMode.isChecked();
  String version="";
  try {
    PackageInfo info=getPackageManager().getPackageInfo(getPackageName(),0);
    version="Version " + info.versionName;
  }
 catch (  NameNotFoundException e) {
    Log.e(TAG,"Could not find version info.");
  }
  if (!isDebugMode) {
    mDebugMode.setTitle(version);
    mDebugMode.setSummary("");
  }
 else {
    mDebugMode.setTitle(getResources().getString(R.string.prefs_debug_mode));
    mDebugMode.setSummary(version);
  }
}
 

Example 100

From project iJetty, under directory /console/apk/src/org/mortbay/ijetty/console/.

Source file: InstallerActivity.java

  17 
vote

public void onCreate(Bundle icicle){
  super.onCreate(icicle);
  setContentView(R.layout.installer);
  installButton=(Button)findViewById(R.id.install);
  versionView=(TextView)findViewById(R.id.version);
  progressDialog=null;
  try {
    PackageInfo pi=getPackageManager().getPackageInfo(getPackageName(),0);
    versionView.setText(Html.fromHtml(String.format("Version %s (%s)",pi.versionName,pi.versionCode)));
  }
 catch (  NameNotFoundException e) {
    versionView.setText("Version ? (?)");
  }
  installButton.setOnClickListener(new OnClickListener(){
    public void onClick(    View v){
      File jettyDir=getJettyInstallDir();
      if (jettyDir == null) {
        showError(getString(R.string.notInstalled));
      }
 else {
        File webapp=getWebApp();
        if (webapp == null) {
          install();
        }
 else {
          showDialog(CONFIRM_DIALOG_ID);
        }
      }
    }
  }
);
}
 

Example 101

From project LitHub, under directory /LitHub-Android/src/us/lithub/ui/activity/.

Source file: MainMenu.java

  17 
vote

private void checkVersion(){
  try {
    final PackageInfo pInfo=getPackageManager().getPackageInfo(getPackageName(),PackageManager.GET_META_DATA);
    final SharedPreferences prefs=getPreferences(Context.MODE_PRIVATE);
    final int lastRunVersionCode=prefs.getInt("lastRunVersionCode",0);
    if (lastRunVersionCode == 0) {
      Log.d(TAG,"New install");
      newInstall();
    }
 else     if (lastRunVersionCode < pInfo.versionCode) {
      Log.d(TAG,"New update");
      newUpdate();
    }
 else {
      Log.d(TAG,"Current");
      foo();
      current();
      bar();
      return;
    }
    final Editor editor=prefs.edit();
    editor.putInt("lastRunVersionCode",pInfo.versionCode);
    editor.commit();
  }
 catch (  NameNotFoundException e) {
    Log.e(TAG,"Error checking version: " + e.getMessage());
  }
}
 

Example 102

From project LoL-Chat, under directory /src/com/rei/lolchat/ui/.

Source file: Login.java

  17 
vote

/** 
 * Create an about "BEEM" dialog.
 */
private void createAboutDialog(){
  AlertDialog.Builder builder=new AlertDialog.Builder(this);
  String versionname;
  try {
    PackageManager pm=getPackageManager();
    PackageInfo pi=pm.getPackageInfo("com.rei.lolchat",0);
    versionname=pi.versionName;
  }
 catch (  PackageManager.NameNotFoundException e) {
    versionname="";
  }
  String title=getString(R.string.login_about_title,versionname);
  builder.setTitle(title).setMessage(R.string.login_about_msg).setCancelable(false);
  builder.setNeutralButton(R.string.login_about_button,new DialogInterface.OnClickListener(){
    public void onClick(    DialogInterface dialog,    int whichButton){
      dialog.cancel();
    }
  }
);
  AlertDialog aboutDialog=builder.create();
  aboutDialog.show();
}
 

Example 103

From project mediautilities, under directory /src/ac/robinson/util/.

Source file: IOUtilities.java

  17 
vote

@SuppressLint("SdCardPath") public static boolean isInstalledOnSdCard(Context context){
  if (VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) {
    PackageManager packageManager=context.getPackageManager();
    try {
      PackageInfo packageInfo=packageManager.getPackageInfo(context.getPackageName(),0);
      ApplicationInfo applicationInfo=packageInfo.applicationInfo;
      return (applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == ApplicationInfo.FLAG_EXTERNAL_STORAGE;
    }
 catch (    NameNotFoundException e) {
    }
  }
  try {
    String filesDir=context.getFilesDir().getAbsolutePath();
    if (filesDir.startsWith("/data/")) {
      return false;
    }
 else     if (filesDir.contains("/mnt/") || filesDir.contains("/sdcard/")) {
      return true;
    }
  }
 catch (  Throwable e) {
  }
  return false;
}
 

Example 104

From project Mobile-Tour-Guide, under directory /zxing-2.0/android/src/com/google/zxing/client/android/.

Source file: CaptureActivity.java

  17 
vote

/** 
 * We want the help screen to be shown automatically the first time a new version of the app is run. The easiest way to do this is to check android:versionCode from the manifest, and compare it to a value stored as a preference.
 */
private boolean showHelpOnFirstLaunch(){
  try {
    PackageInfo info=getPackageManager().getPackageInfo(PACKAGE_NAME,0);
    int currentVersion=info.versionCode;
    this.versionName=info.versionName;
    SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this);
    int lastVersion=prefs.getInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN,0);
    if (currentVersion > lastVersion) {
      prefs.edit().putInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN,currentVersion).commit();
      Intent intent=new Intent(this,HelpActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
      String page=lastVersion == 0 ? HelpActivity.DEFAULT_PAGE : HelpActivity.WHATS_NEW_PAGE;
      intent.putExtra(HelpActivity.REQUESTED_PAGE_KEY,page);
      startActivity(intent);
      return true;
    }
  }
 catch (  PackageManager.NameNotFoundException e) {
    Log.w(TAG,e);
  }
  return false;
}
 

Example 105

From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/applications/.

Source file: InstalledAppDetails.java

  15 
vote

private void setAppLabelAndIcon(PackageInfo pkgInfo){
  View appSnippet=findViewById(R.id.app_snippet);
  ImageView icon=(ImageView)appSnippet.findViewById(R.id.app_icon);
  mState.ensureIcon(mAppEntry);
  icon.setImageDrawable(mAppEntry.icon);
  TextView label=(TextView)appSnippet.findViewById(R.id.app_name);
  label.setText(mAppEntry.label);
  mAppVersion=(TextView)appSnippet.findViewById(R.id.app_size);
  if (pkgInfo != null && pkgInfo.versionName != null) {
    mAppVersion.setVisibility(View.VISIBLE);
    mAppVersion.setText(getString(R.string.version_text,String.valueOf(pkgInfo.versionName)));
  }
 else {
    mAppVersion.setVisibility(View.INVISIBLE);
  }
}
 

Example 106

From project android_packages_apps_cmparts, under directory /src/com/cyanogenmod/cmparts/activities/led/.

Source file: NotificationActivity.java

  15 
vote

private List<PackageInfo> getPackageList(){
  PackageManager packageManager=getPackageManager();
  List<PackageInfo> packs=packageManager.getInstalledPackages(0);
  List<PackageInfo> list=new ArrayList<PackageInfo>();
  SharedPreferences pkgPrefs=getSharedPreferences("led_packages",Context.MODE_PRIVATE);
  for (  PackageInfo p : packs) {
    try {
      String pkg=p.packageName;
      if (pkgPrefs.getString(pkg,null) != null || knownPackage(pkg) != null) {
        list.add(p);
      }
    }
 catch (    Exception e) {
      Log.d("GetPackageList",e.toString());
    }
  }
  return list;
}
 

Example 107

From project Cafe, under directory /testservice/src/com/baidu/cafe/remote/.

Source file: SystemLib.java

  15 
vote

/** 
 * check whether an app is installed or not
 * @param packageName : package name
 * @return true if installed already
 */
public boolean isPackageInstalled(String packageName){
  boolean flag=false;
  List<PackageInfo> packageInfoList=mPackageManager.getInstalledPackages(0);
  for (int i=0; i < packageInfoList.size(); i++) {
    if (packageName.equals(packageInfoList.get(i).packageName)) {
      flag=true;
      break;
    }
  }
  if (isregister == true) {
    mContext.unregisterReceiver(mReceiver);
    isregister=false;
  }
  return flag;
}
 

Example 108

From project COSsettings, under directory /src/com/cyanogenmod/cmparts/activities/led/.

Source file: NotificationActivity.java

  15 
vote

private List<PackageInfo> getPackageList(){
  PackageManager packageManager=getPackageManager();
  List<PackageInfo> packs=packageManager.getInstalledPackages(0);
  List<PackageInfo> list=new ArrayList<PackageInfo>();
  SharedPreferences pkgPrefs=getSharedPreferences("led_packages",Context.MODE_PRIVATE);
  for (  PackageInfo p : packs) {
    try {
      String pkg=p.packageName;
      if (pkgPrefs.getString(pkg,null) != null || knownPackage(pkg) != null) {
        list.add(p);
      }
    }
 catch (    Exception e) {
      Log.d("GetPackageList",e.toString());
    }
  }
  return list;
}
 

Example 109

From project creamed_glacier_app_settings, under directory /src/com/android/settings/applications/.

Source file: InstalledAppDetails.java

  15 
vote

private void setAppLabelAndIcon(PackageInfo pkgInfo){
  View appSnippet=mRootView.findViewById(R.id.app_snippet);
  ImageView icon=(ImageView)appSnippet.findViewById(R.id.app_icon);
  mState.ensureIcon(mAppEntry);
  icon.setImageDrawable(mAppEntry.icon);
  TextView label=(TextView)appSnippet.findViewById(R.id.app_name);
  label.setText(mAppEntry.label);
  mAppVersion=(TextView)appSnippet.findViewById(R.id.app_size);
  if (pkgInfo != null && pkgInfo.versionName != null) {
    mAppVersion.setVisibility(View.VISIBLE);
    mAppVersion.setText(getActivity().getString(R.string.version_text,String.valueOf(pkgInfo.versionName)));
  }
 else {
    mAppVersion.setVisibility(View.INVISIBLE);
  }
}
 

Example 110

From project cw-advandroid, under directory /Tapjacking/TJDetect/src/com/commonsware/android/tj/detect/.

Source file: TJDetect.java

  15 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  ActivityManager am=(ActivityManager)getSystemService(ACTIVITY_SERVICE);
  HashSet<CharSequence> runningPackages=new HashSet<CharSequence>();
  for (  ActivityManager.RunningAppProcessInfo proc : am.getRunningAppProcesses()) {
    for (    String pkgName : proc.pkgList) {
      runningPackages.add(pkgName);
    }
  }
  PackageManager mgr=getPackageManager();
  ArrayList<CharSequence> scary=new ArrayList<CharSequence>();
  for (  PackageInfo pkg : mgr.getInstalledPackages(PackageManager.GET_PERMISSIONS)) {
    if (PackageManager.PERMISSION_GRANTED == mgr.checkPermission(android.Manifest.permission.SYSTEM_ALERT_WINDOW,pkg.packageName)) {
      if (PackageManager.PERMISSION_GRANTED == mgr.checkPermission(android.Manifest.permission.INTERNET,pkg.packageName)) {
        if (runningPackages.contains(pkg.packageName)) {
          scary.add(mgr.getApplicationLabel(pkg.applicationInfo));
        }
      }
    }
  }
  setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,scary));
}
 

Example 111

From project cw-omnibus, under directory /Tapjacking/TJDetect/src/com/commonsware/android/tj/detect/.

Source file: TJDetect.java

  15 
vote

@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  ActivityManager am=(ActivityManager)getSystemService(ACTIVITY_SERVICE);
  HashSet<CharSequence> runningPackages=new HashSet<CharSequence>();
  for (  ActivityManager.RunningAppProcessInfo proc : am.getRunningAppProcesses()) {
    for (    String pkgName : proc.pkgList) {
      runningPackages.add(pkgName);
    }
  }
  PackageManager mgr=getPackageManager();
  ArrayList<CharSequence> scary=new ArrayList<CharSequence>();
  for (  PackageInfo pkg : mgr.getInstalledPackages(PackageManager.GET_PERMISSIONS)) {
    if (PackageManager.PERMISSION_GRANTED == mgr.checkPermission(android.Manifest.permission.SYSTEM_ALERT_WINDOW,pkg.packageName)) {
      if (PackageManager.PERMISSION_GRANTED == mgr.checkPermission(android.Manifest.permission.INTERNET,pkg.packageName)) {
        if (runningPackages.contains(pkg.packageName)) {
          scary.add(mgr.getApplicationLabel(pkg.applicationInfo));
        }
      }
    }
  }
  setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1,scary));
}
 

Example 112

From project farebot, under directory /src/com/codebutler/farebot/.

Source file: Utils.java

  15 
vote

private static PackageInfo getPackageInfo(){
  try {
    FareBotApplication app=FareBotApplication.getInstance();
    return app.getPackageManager().getPackageInfo(app.getPackageName(),0);
  }
 catch (  PackageManager.NameNotFoundException e) {
    throw new RuntimeException(e);
  }
}
 

Example 113

From project locale-calendar-plugin, under directory /plugin/src/main/java/com/twofortyfouram/locale/.

Source file: PackageUtilities.java

  15 
vote

/** 
 * Obtains the  {@code String} package name of a currently-installed package which implements the host component of the<i>Locale</i> Developer Platform. <p> Note: A TOCTOU error exists, due to the fact that the package could be uninstalled at any time. <p> Note: If there are multiple hosts, this method will return one of them. The interface of this method makes no guarantee which host will returned, nor whether that host will be consistently returned.
 * @param manager an instance of {@code PackageManager}. Cannot be null.
 * @param packageHint hint as to which package should take precedence. This parameter may be null.
 * @return {@code String} package name of a host for the <i>Locale</i> Developer Platform, such as"com.twofortyfouram.locale". If no such package is found, returns null.
 */
static String getCompatiblePackage(final PackageManager manager,final String packageHint){
  final List<PackageInfo> installedPackages=manager.getInstalledPackages(0);
  if (COMPATIBLE_PACKAGES.contains(packageHint)) {
    for (    final PackageInfo packageInfo : installedPackages) {
      final String temp=packageInfo.packageName;
      if (packageHint.equals(temp)) {
        return temp;
      }
    }
  }
  for (  final String compatiblePackageName : COMPATIBLE_PACKAGES) {
    if (compatiblePackageName.equals(packageHint)) {
      continue;
    }
    for (    final PackageInfo packageInfo : installedPackages) {
      final String temp=packageInfo.packageName;
      if (compatiblePackageName.equals(temp)) {
        return temp;
      }
    }
  }
  return null;
}