Java Code Examples for android.content.pm.PackageManager.NameNotFoundException
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 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.
Source file: AboutDialog.java

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 2
From project ActionBarCompat, under directory /ActionBarCompat/src/sk/m217/actionbarcompat/.
Source file: ActionBarHelperBase.java

/** * Sets up the compatibility action bar with the given title. */ private void setupActionBar(){ final ViewGroup actionBarCompat=getActionBarCompat(); if (actionBarCompat == null) { return; } mHomeItem=new SimpleMenuItem(new SimpleMenu(mActivity),android.R.id.home,0,mActivity.getTitle()); final LayoutInflater inflater=LayoutInflater.from(mActivity); mHomeLayout=(HomeView)inflater.inflate(R.layout.actionbar_compat_home,actionBarCompat,false); mHomeLayout.setOnClickListener(mUpClickListener); mHomeLayout.setClickable(true); mHomeLayout.setFocusable(true); mExpandedHomeLayout=(HomeView)inflater.inflate(R.layout.actionbar_compat_home,actionBarCompat,false); mExpandedHomeLayout.setUp(true); mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener); mExpandedHomeLayout.setContentDescription(mActivity.getResources().getText(R.string.action_bar_up_description)); mExpandedHomeLayout.setFocusable(true); ApplicationInfo appInfo=mActivity.getApplicationInfo(); PackageManager pm=mActivity.getPackageManager(); try { mIcon=pm.getActivityIcon(mActivity.getComponentName()); } catch ( NameNotFoundException e) { Log.e(TAG,"Activity component name not found!",e); } if (mIcon == null) { mIcon=appInfo.loadIcon(pm); } mHomeLayout.setIcon(mIcon); actionBarCompat.addView(mHomeLayout); LinearLayout.LayoutParams springLayoutParams=new LinearLayout.LayoutParams(0,ViewGroup.LayoutParams.FILL_PARENT); springLayoutParams.weight=1; mTitle=mActivity.getTitle(); mTitleText=new TextView(mActivity,null,R.attr.actionbarCompatTitleStyle); mTitleText.setLayoutParams(springLayoutParams); mTitleText.setText(mTitle); actionBarCompat.addView(mTitleText); setDisplayOptions(DISPLAY_SHOW_HOME | DISPLAY_SHOW_TITLE); }
Example 3
From project cornerstone, under directory /frameworks/base/services/java/com/android/server/am/.
Source file: ActivityManagerService.java

public static void setSystemProcess(){ try { ActivityManagerService m=mSelf; ServiceManager.addService("activity",m); ServiceManager.addService("meminfo",new MemBinder(m)); ServiceManager.addService("gfxinfo",new GraphicsBinder(m)); if (MONITOR_CPU_USAGE) { ServiceManager.addService("cpuinfo",new CpuBinder(m)); } ServiceManager.addService("permission",new PermissionController(m)); ApplicationInfo info=mSelf.mContext.getPackageManager().getApplicationInfo("android",STOCK_PM_FLAGS); mSystemThread.installSystemApplicationInfo(info); synchronized (mSelf) { ProcessRecord app=mSelf.newProcessRecordLocked(mSystemThread.getApplicationThread(),info,info.processName); app.persistent=true; app.pid=MY_PID; app.maxAdj=ProcessList.SYSTEM_ADJ; mSelf.mProcessNames.put(app.processName,app.info.uid,app); synchronized (mSelf.mPidsSelfLocked) { mSelf.mPidsSelfLocked.put(app.pid,app); } mSelf.updateLruProcessLocked(app,true,true); } } catch ( PackageManager.NameNotFoundException e) { throw new RuntimeException("Unable to find android system package",e); } }
Example 4
From project creamed_glacier_app_settings, under directory /src/com/android/settings/.
Source file: ActivityPicker.java

/** * Build and return list of items to be shown in dialog. Default implementation mixes activities matching {@link #mBaseIntent} from{@link #putIntentItems(Intent,List)} with any injected items from{@link Intent#EXTRA_SHORTCUT_NAME}. Override this method in subclasses to change the items shown. */ protected List<PickAdapter.Item> getItems(){ PackageManager packageManager=getPackageManager(); List<PickAdapter.Item> items=new ArrayList<PickAdapter.Item>(); final Intent intent=getIntent(); ArrayList<String> labels=intent.getStringArrayListExtra(Intent.EXTRA_SHORTCUT_NAME); ArrayList<ShortcutIconResource> icons=intent.getParcelableArrayListExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); if (labels != null && icons != null && labels.size() == icons.size()) { for (int i=0; i < labels.size(); i++) { String label=labels.get(i); Drawable icon=null; try { ShortcutIconResource iconResource=icons.get(i); Resources res=packageManager.getResourcesForApplication(iconResource.packageName); icon=res.getDrawable(res.getIdentifier(iconResource.resourceName,null,null)); } catch ( NameNotFoundException e) { } items.add(new PickAdapter.Item(this,label,icon)); } } if (mBaseIntent != null) { putIntentItems(mBaseIntent,items); } return items; }
Example 5
From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/widget/.
Source file: SuggestionsAdapter.java

public Drawable getTheDrawable(Uri uri) throws FileNotFoundException { String authority=uri.getAuthority(); Resources r; if (TextUtils.isEmpty(authority)) { throw new FileNotFoundException("No authority: " + uri); } else { try { r=mContext.getPackageManager().getResourcesForApplication(authority); } catch ( NameNotFoundException ex) { throw new FileNotFoundException("No package found for authority: " + uri); } } List<String> path=uri.getPathSegments(); if (path == null) { throw new FileNotFoundException("No path: " + uri); } int len=path.size(); int id; if (len == 1) { try { id=Integer.parseInt(path.get(0)); } catch ( NumberFormatException e) { throw new FileNotFoundException("Single path segment is not a resource ID: " + uri); } } else if (len == 2) { id=r.getIdentifier(path.get(1),path.get(0),authority); } else { throw new FileNotFoundException("More than two path segments: " + uri); } if (id == 0) { throw new FileNotFoundException("No resource found for: " + uri); } return r.getDrawable(id); }
Example 6
From project and-bible, under directory /AndBible/src/net/bible/service/common/.
Source file: CommonUtils.java

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 7
From project andlytics, under directory /src/com/github/andlyticsproject/.
Source file: BaseActivity.java

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 8
From project Android, under directory /AndroidNolesCore/src/util/.
Source file: XMLParserConnection.java

/** * 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 9
From project android-bankdroid, under directory /src/com/liato/bankdroid/.
Source file: AboutActivity.java

@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 10
@Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.about); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.abouttitle); TextView versionTextView=(TextView)findViewById(R.id.version); try { versionTextView.setText(getString(R.string.version) + " " + getPackageManager().getPackageInfo(getPackageName(),0).versionName); } catch ( NameNotFoundException e) { } aboutAdapter=new AboutAdapter(this); generateDevelopmentItems(); generateMoreInfoItems(); setListAdapter(aboutAdapter); }
Example 11
From project Android-File-Manager, under directory /src/com/nexes/manager/.
Source file: ApplicationBackup.java

@Override public View getView(int position,View convertView,ViewGroup parent){ AppViewHolder holder; ApplicationInfo info=mAppList.get(position); if (convertView == null) { LayoutInflater inflater=getLayoutInflater(); convertView=inflater.inflate(R.layout.tablerow,parent,false); holder=new AppViewHolder(); holder.top_view=(TextView)convertView.findViewById(R.id.top_view); holder.bottom_view=(TextView)convertView.findViewById(R.id.bottom_view); holder.check_mark=(ImageView)convertView.findViewById(R.id.multiselect_icon); holder.icon=(ImageView)convertView.findViewById(R.id.row_image); holder.icon.setMaxHeight(40); convertView.setTag(holder); } else { holder=(AppViewHolder)convertView.getTag(); } holder.top_view.setText(info.processName); holder.bottom_view.setText(info.packageName); try { holder.icon.setImageDrawable(mPackMag.getApplicationIcon(info.packageName)); } catch ( NameNotFoundException e) { holder.icon.setImageResource(R.drawable.appicon); } return convertView; }
Example 12
From project android-flash-cards, under directory /src/org/thomasamsler/android/flashcards/fragment/.
Source file: AboutFragment.java

@Override public void onActivityCreated(Bundle savedInstanceState){ super.onCreate(savedInstanceState); String version=null; try { version=getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(),0).versionName; } catch ( NameNotFoundException e) { Log.w(AppConstants.LOG_TAG,"Exception accessing version information",e); } TextView versionTextView=(TextView)getActivity().findViewById(R.id.textViewAboutVersion); versionTextView.append(version); ImageButton imageButtonCancel=(ImageButton)getActivity().findViewById(R.id.imageButtonAboutClose); imageButtonCancel.setOnClickListener(new OnClickListener(){ public void onClick( View v){ ((MainApplication)getActivity().getApplication()).doAction(ACTION_SHOW_CARD_SETS,Boolean.TRUE); } } ); }
Example 13
From project android-joedayz, under directory /Proyectos/FBConnectTest/src/com/facebook/android/.
Source file: Facebook.java

/** * 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 14
From project android-sdk, under directory /src/main/java/com/mobeelizer/mobile/android/.
Source file: MobeelizerApplication.java

private Bundle getMetaData(final Application mobeelizer){ try { return mobeelizer.getPackageManager().getApplicationInfo(mobeelizer.getPackageName(),PackageManager.GET_META_DATA).metaData; } catch ( NameNotFoundException e) { throw new IllegalStateException(e.getMessage(),e); } }
Example 15
From project Android-Simple-Social-Sharing, under directory /SimpleSocialSharing/src/com/nostra13/socialsharing/facebook/extpack/com/facebook/android/.
Source file: Facebook.java

/** * 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 16
From project android-tether, under directory /facebook/src/com/facebook/android/.
Source file: Facebook.java

/** * 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 intent * @param validSignature * @return true if the app's signature matches the expected signature. */ private boolean validateAppSignatureForIntent(Context context,Intent intent){ ResolveInfo resolveInfo=context.getPackageManager().resolveActivity(intent,0); if (resolveInfo == null) { return false; } String packageName=resolveInfo.activityInfo.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 17
From project android-thaiime, under directory /latinime/src/com/sugree/inputmethod/latin/.
Source file: BinaryDictionaryGetter.java

public DictPackSettings(final Context context){ Context dictPackContext=null; try { final String dictPackName=context.getString(R.string.dictionary_pack_package_name); dictPackContext=context.createPackageContext(dictPackName,0); } catch ( NameNotFoundException e) { Log.e(TAG,"Could not find a dictionary pack"); } mDictPreferences=null == dictPackContext ? null : dictPackContext.getSharedPreferences(COMMON_PREFERENCES_NAME,Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS); }
Example 18
From project android-voip-service, under directory /src/main/java/org/linphone/.
Source file: AboutActivity.java

public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.about); aboutText=(TextView)findViewById(R.id.AboutText); try { aboutText.setText(String.format(getString(R.string.about_text),getPackageManager().getPackageInfo(getPackageName(),0).versionName)); } catch ( NameNotFoundException e) { Log.e(e,"cannot get version name"); } }
Example 19
From project android-xbmcremote, under directory /src/org/xbmc/android/remote/presentation/activity/.
Source file: AboutActivity.java

@Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.about); final Display display=getWindowManager().getDefaultDisplay(); ThumbSize.setScreenSize(display.getWidth(),display.getHeight()); try { mEventClientManager=ManagerFactory.getEventClientManager(null); final String versionName=getPackageManager().getPackageInfo(getPackageName(),0).versionName; final int versionCode=getPackageManager().getPackageInfo(getPackageName(),0).versionCode; ((TextView)findViewById(R.id.about_version)).setText("v" + versionName); ((TextView)findViewById(R.id.about_revision)).setText("Revision " + versionCode); TextView message=(TextView)findViewById(R.id.about_url_message); message.setText(Html.fromHtml("Visit our project page at <a href=\"http://code.google.com/p/android-xbmcremote\">Google Code</a>.")); message.setMovementMethod(LinkMovementMethod.getInstance()); } catch ( NameNotFoundException e) { ((TextView)findViewById(R.id.about_version)).setText("Error reading version"); } mConfigurationManager=ConfigurationManager.getInstance(this); }
Example 20
From project AndroidCommon, under directory /src/com/asksven/android/common/nameutils/.
Source file: UidNameResolver.java

public String getLabel(Context context,String packageName){ String ret=packageName; PackageManager pm=context.getPackageManager(); try { ApplicationInfo ai=pm.getApplicationInfo(packageName,0); CharSequence label=ai.loadLabel(pm); if (label != null) { ret=label.toString(); } } catch ( NameNotFoundException e) { ret=packageName; } return ret; }
Example 21
From project androidquery, under directory /auth/com/androidquery/auth/.
Source file: FacebookHandle.java

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 22
From project Android_1, under directory /LeftNavBarExample/LeftNavBarLibrary/src/com/example/google/tv/leftnavbar/.
Source file: HomeDisplay.java

private void loadLogo(TypedArray a,PackageManager pm,ApplicationInfo appInfo){ if (mContext instanceof Activity) { try { mLogo=pm.getActivityLogo(((Activity)mContext).getComponentName()); } catch ( NameNotFoundException e) { Log.e(TAG,"Failed to load app logo.",e); } } if (mLogo == null) { mLogo=appInfo.loadLogo(pm); } }
Example 23
From project android_7, under directory /src/org/immopoly/android/app/.
Source file: ImmopolyActivity.java

public String getVersionInfo(){ try { return getPackageManager().getPackageInfo(getPackageName(),0).versionName + " (" + getPackageManager().getPackageInfo(getPackageName(),0).versionCode+ ")"; } catch ( NameNotFoundException e) { return ""; } }
Example 24
From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/.
Source file: AccessibilitySettings.java

/** * Displays a message telling the user that they do not have any accessibility related apps installed and that they can get TalkBack (Google's free screen reader) from Market. */ private void displayNoAppsAlert(){ try { PackageManager pm=getPackageManager(); ApplicationInfo info=pm.getApplicationInfo("com.android.vending",0); } catch ( NameNotFoundException e) { return; } AlertDialog.Builder noAppsAlert=new AlertDialog.Builder(this); noAppsAlert.setTitle(R.string.accessibility_service_no_apps_title); noAppsAlert.setMessage(R.string.accessibility_service_no_apps_message); noAppsAlert.setPositiveButton(android.R.string.ok,new DialogInterface.OnClickListener(){ public void onClick( DialogInterface dialog, int which){ String screenreaderMarketLink=SystemProperties.get("ro.screenreader.market",DEFAULT_SCREENREADER_MARKET_LINK); Uri marketUri=Uri.parse(screenreaderMarketLink); Intent marketIntent=new Intent(Intent.ACTION_VIEW,marketUri); startActivity(marketIntent); finish(); } } ); noAppsAlert.setNegativeButton(android.R.string.cancel,new DialogInterface.OnClickListener(){ public void onClick( DialogInterface dialog, int which){ } } ); noAppsAlert.show(); }
Example 25
From project android_packages_apps_FileManager, under directory /src/org/openintents/distribution/.
Source file: UpdateDialog.java

/** * 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 26
From project android_packages_apps_Gallery2, under directory /gallerycommon/src/com/android/gallery3d/common/.
Source file: HttpClientFactory.java

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 27
From project android_packages_apps_Nfc, under directory /src/com/android/nfc/.
Source file: NfceeAccessControl.java

/** * 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 28
From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/.
Source file: PackageIconLoader.java

private boolean ensurePackageContext(){ if (mPackageContext == null) { try { mPackageContext=mContext.createPackageContext(mPackageName,Context.CONTEXT_RESTRICTED); } catch ( PackageManager.NameNotFoundException ex) { Log.e(TAG,"Application not found " + mPackageName); return false; } } return true; }
Example 29
From project android_packages_apps_Superuser, under directory /src/com/noshufou/android/su/.
Source file: InstallReceiver.java

@Override public void onReceive(Context context,Intent intent){ PackageManager pm=context.getPackageManager(); String packageName=intent.getDataString().split(":")[1]; PackageInfo packageInfo=null; try { packageInfo=pm.getPackageInfo(packageName,PackageManager.GET_PERMISSIONS); } catch ( NameNotFoundException e) { Log.e(TAG,"PackageManager divided by zero...",e); return; } if (Util.isPackageMalicious(context,packageInfo) != 0) { NotificationManager nm=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); Notification notification=new Notification(R.drawable.stat_su,context.getString(R.string.malicious_app_notification_ticker),System.currentTimeMillis()); CharSequence contentTitle=context.getString(R.string.app_name); CharSequence contentText=context.getString(R.string.malicious_app_notification_text,pm.getApplicationLabel(packageInfo.applicationInfo)); Intent notificationIntent=new Intent(Intent.ACTION_DELETE,intent.getData()); PendingIntent contentIntent=PendingIntent.getActivity(context,0,notificationIntent,0); notification.setLatestEventInfo(context,contentTitle,contentText,contentIntent); notification.flags|=Notification.FLAG_AUTO_CANCEL; nm.notify(0,notification); } }
Example 30
From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/latin/.
Source file: BinaryDictionaryGetter.java

public DictPackSettings(final Context context){ Context dictPackContext=null; try { final String dictPackName=context.getString(R.string.dictionary_pack_package_name); dictPackContext=context.createPackageContext(dictPackName,0); } catch ( NameNotFoundException e) { Log.e(TAG,"Could not find a dictionary pack"); } mDictPreferences=null == dictPackContext ? null : dictPackContext.getSharedPreferences(COMMON_PREFERENCES_NAME,Context.MODE_WORLD_READABLE | Context.MODE_MULTI_PROCESS); }
Example 31
From project androlog, under directory /androlog/src/main/java/de/akquinet/android/androlog/reporter/.
Source file: Report.java

/** * 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 32
From project Anki-Android, under directory /src/com/tomgibara/android/veecheck/.
Source file: VeecheckVersion.java

/** * Constructs a version that draws all of its properties from the supplied context. * @param context the context from which version properties will be drawn */ VeecheckVersion(Context context){ try { PackageManager manager=context.getPackageManager(); PackageInfo info=manager.getPackageInfo(context.getPackageName(),0); packageName=info.packageName; versionCode=Integer.toString(info.versionCode); versionName=info.versionName; } catch ( NameNotFoundException e) { Log.w(LOG_TAG,"Unable to obtain package info: ",e); } buildBrand=Build.BRAND; buildId=Build.ID; buildModel=Build.MODEL; }
Example 33
From project AnySoftKeyboard, under directory /src/com/anysoftkeyboard/addons/.
Source file: AddOnsFactory.java

public static void onPackageChanged(final Intent eventIntent,final AnySoftKeyboard ask){ boolean cleared=false; boolean recreateView=false; for ( AddOnsFactory<?> factory : mActiveInstances) { try { if (factory.isEventRequiresCacheRefresh(eventIntent,ask.getApplicationContext())) { cleared=true; if (factory.isEventRequiresViewReset(eventIntent,ask.getApplicationContext())) recreateView=true; if (AnyApplication.DEBUG) Log.d("AddOnsFactory",factory.getClass().getName() + " will handle this package-changed event. Also recreate view? " + recreateView); factory.clearAddOnList(); } } catch ( NameNotFoundException e) { e.printStackTrace(); } } if (cleared) ask.resetKeyboardView(recreateView); }
Example 34
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 35
From project apps-for-android, under directory /BTClickLinkCompete/src/net/clc/bt/.
Source file: ConnectionService.java

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 36
From project AquaNotesTest, under directory /src/com/google/android/apps/iosched/service/.
Source file: SyncService.java

/** * 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 37
From project BazaarUtils, under directory /src/com/android/vending/licensing/.
Source file: LicenseChecker.java

/** * Get version code for the application package name. * @param context * @param packageName application package name * @return the version code or empty string if package not found */ private static String getVersionCode(Context context,String packageName){ try { return String.valueOf(context.getPackageManager().getPackageInfo(packageName,0).versionCode); } catch ( NameNotFoundException e) { Log.e(TAG,"Package not found. could not get version code."); return ""; } }
Example 38
From project be.norio.twunch.android, under directory /src/be/norio/twunch/android/service/.
Source file: SyncService.java

/** * 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 39
From project BibleQuote-for-Android, under directory /src/com/BibleQuote/utils/.
Source file: Log.java

/** * ?????????? ?????-????????? ???????. ???????? ?????? ?????, ?????? ??????? ????, ?????? ?????????, ????? ??????? * @param context */ public static void Init(Context context){ String state=Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { logFile=new File(DataConstants.FS_APP_DIR_NAME,"log.txt"); if (logFile.exists()) { logFile.delete(); } String myversion; try { myversion=context.getPackageManager().getPackageInfo(context.getPackageName(),0).versionName; } catch ( NameNotFoundException e) { myversion="0.00.01"; } Write("Log " + new SimpleDateFormat("dd-MMM-yy G hh:mm aaa").format(Calendar.getInstance().getTime())); Write("Current version package: " + myversion); Write("Default language: " + Locale.getDefault().getDisplayLanguage()); Write("Device model: " + android.os.Build.BRAND + " "+ android.os.Build.MODEL); Write("Device display: " + android.os.Build.BRAND + " "+ android.os.Build.DISPLAY); Write("Android OS: " + android.os.Build.VERSION.RELEASE); Write("===================================="); } }
Example 40
From project Birthday-widget, under directory /Birthday/src/main/java/cz/krtinec/birthday/.
Source file: Birthday.java

/** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); try { int version=this.getPackageManager().getPackageInfo("cz.krtinec.birthday",0).versionCode; SharedPreferences prefs=PreferenceManager.getDefaultSharedPreferences(this); if (version != prefs.getInt(VERSION_KEY,1)) { Utils.setOrCancelNotificationsAlarm(this,prefs); Editor editor=prefs.edit(); editor.putInt(VERSION_KEY,version); editor.commit(); } } catch ( NameNotFoundException e) { } }
Example 41
From project Birthdays, under directory /src/com/rexmenpara/birthdays/.
Source file: BirthdaysActivity.java

@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 42
From project Bitcoin-Wallet-for-Android, under directory /wallet/src/de/schildbach/wallet/util/.
Source file: ErrorReporter.java

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 43
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 44
From project bookmarktodesktop-android-application, under directory /src/be/vbsteven/bmtodesk/.
Source file: Licensing.java

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 45
From project box-android-sdk, under directory /OneCloudAppToApp/src/com/box/onecloud/android/.
Source file: OneCloudData.java

/** * Trigger a handshake between us and the Box app. * @param context Context. */ public void sendHandshake(final Context context){ try { mBoxAppVersionCode=context.getPackageManager().getPackageInfo(BoxOneCloudReceiver.BOX_PACKAGE_NAME,0).versionCode; } catch ( NameNotFoundException e1) { return; } HandshakeCallback handshake=new HandshakeCallback.Stub(){ @Override public void onShake() throws RemoteException { String[] packages=context.getPackageManager().getPackagesForUid(Binder.getCallingUid()); if (packages.length == 1 && packages[0].equals(BoxOneCloudReceiver.BOX_PACKAGE_NAME)) { mHandshaken=true; } } } ; try { mBinder.sendHandshake(handshake); } catch ( RemoteException e) { } }
Example 46
From project BSPAN---Bluetooth-Sensor-Processing-for-Android, under directory /AndroidBTService/src/com/t2/biofeedback/activity/.
Source file: BTServiceManager.java

@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 47
/** * onCreate - initializes a settings screen */ @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); if (BuzzWordsApplication.DEBUG) { Log.d(TAG,"onCreate()"); } mContinueMusic=false; setVolumeControlStream(AudioManager.STREAM_MUSIC); this.addPreferencesFromResource(R.xml.settings); this.updateTimerLabel(); Preference version=findPreference("app_version"); try { version.setTitle(this.getString(R.string.AppName)); version.setSummary(" Version " + this.getPackageManager().getPackageInfo(this.getPackageName(),0).versionName); } catch ( NameNotFoundException e) { e.printStackTrace(); Log.e(TAG,e.getMessage()); } }
Example 48
From project Cafe, under directory /testrunner/src/com/baidu/cafe/local/.
Source file: LocalLib.java

/** * get all class names from a package via its dex file * @param packageName e.g. "com.baidu.chunlei.exercise.test" * @return names of classes */ public ArrayList<String> getAllClassNamesFromPackage(String packageName){ ArrayList<String> classes=new ArrayList<String>(); try { String path=mContext.getPackageManager().getApplicationInfo(packageName,PackageManager.GET_META_DATA).sourceDir; DexFile dexfile=new DexFile(path); Enumeration<String> entries=dexfile.entries(); while (entries.hasMoreElements()) { String name=(String)entries.nextElement(); if (name.indexOf('$') == -1) { classes.add(name); } } } catch ( NameNotFoundException e) { e.printStackTrace(); } catch ( IOException e) { e.printStackTrace(); } return classes; }
Example 49
From project Catroid-maven-playground, under directory /src/main/java/at/tugraz/ist/catroid/utils/.
Source file: Utils.java

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 50
From project CHMI, under directory /src/org/kaldax/lib/net/app/netresource/.
Source file: ActualInfo.java

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 51
From project cicada, under directory /cicada/src/org/cicadasong/cicada/.
Source file: PackageUtil.java

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 52
From project CineShowTime-Android, under directory /Libraries/CineShowTime/src/com/binomed/showtime/android/util/activity/.
Source file: AbstractCineShowTimeActivity.java

@Override public void onPostContentChanged(){ boolean titleSet=false; final Intent intent=getIntent(); if (intent != null) { String title=intent.getStringExtra(ActionBarActivity.GD_ACTION_BAR_TITLE); if (title != null) { titleSet=true; setTitle(title); } } if (!titleSet) { try { final ActivityInfo activityInfo=getPackageManager().getActivityInfo(getComponentName(),0); if (activityInfo.labelRes != 0) { setTitle(activityInfo.labelRes); } } catch ( NameNotFoundException e) { } } final int visibility=intent.getIntExtra(ActionBarActivity.GD_ACTION_BAR_VISIBILITY,View.VISIBLE); getActionBar().setVisibility(visibility); }
Example 53
@Override protected void onCreate(Bundle savedInstanceState){ Log.d(TAG,"onCreate()"); super.onCreate(savedInstanceState); setContentView(R.layout.about); try { String versionName=getPackageManager().getPackageInfo(getPackageName(),0).versionName; TextView versionText=(TextView)findViewById(R.id.about_version_text_view); versionText.setText(versionName); } catch ( NameNotFoundException e) { e.printStackTrace(); } }
Example 54
From project conference-mobile-app, under directory /android-app/src/com/google/android/apps/iosched/service/.
Source file: SyncService.java

/** * 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 55
@Override public void onCreate(Bundle icicle){ super.onCreate(icicle); setContentView(R.layout.act_help); this.setTitle(String.format("%s: %s",getResources().getText(R.string.app_name),getResources().getText(R.string.title_help))); AssetManager am=this.getAssets(); LinearLayout content=(LinearLayout)this.findViewById(R.id.topics); TextView appVersionView=(TextView)this.findViewById(R.id.topics).findViewById(R.id.app_version); try { appVersionView.setText(getPackageManager().getPackageInfo(getPackageName(),0).versionName); } catch ( NameNotFoundException e) { Log.e(TAG,"Problem retrieving application version",e); } try { for ( String name : am.list(HELPDIR)) { if (name.endsWith(SUFFIX)) { Button button=new Button(this); final String topic=name.substring(0,name.length() - SUFFIX.length()); button.setText(topic); button.setOnClickListener(new OnClickListener(){ public void onClick( View v){ Intent intent=new Intent(HelpActivity.this,HelpTopicActivity.class); intent.putExtra(Intent.EXTRA_TITLE,topic); HelpActivity.this.startActivity(intent); } } ); content.addView(button); } } } catch ( IOException e) { Log.e(TAG,"couldn't get list of help assets",e); } }
Example 56
protected void onPreExecute(){ File su=new File("/system/bin/su"); canGetRoot=su.exists(); if (canGetRoot) Log.d(tag,"su command found - will run with root permissions."); else Log.d(tag,"su NOT found - will attempt to run without root permissions."); if (canGetRoot) NmapActivity.setBinDir("/data/local/bin/"); else try { NmapActivity.setBinDir((NmapActivity.this.getPackageManager().getApplicationInfo("com.cura",0).dataDir + "/bin/")); } catch ( NameNotFoundException e) { Log.d(tag,"Unable to set bindir: " + e.toString()); } }
Example 57
From project daily-money, under directory /dailymoney/src/com/bottleworks/dailymoney/context/.
Source file: Contexts.java

/** * 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 58
From project danbooru-gallery-android, under directory /src/tw/idv/palatis/danboorugallery/.
Source file: DanbooruGalleryPreferenceActivity.java

@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 59
From project dccsched, under directory /src/com/underhilllabs/dccsched/service/.
Source file: SyncService.java

/** * 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 60
From project dcnyc10-android, under directory /android/src/com/lullabot/android/apps/iosched/service/.
Source file: SyncService.java

/** * 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 61
From project devoxx-france-android-in-fine, under directory /src/com/infine/android/devoxx/service/.
Source file: RestService.java

/** * 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 62
From project Diktofon, under directory /app/src/kaljurand_at_gmail_dot_com/diktofon/activity/.
Source file: AboutActivity.java

private PackageInfo getPackageInfo(){ PackageManager manager=getPackageManager(); try { return manager.getPackageInfo(getPackageName(),0); } catch ( NameNotFoundException e) { Log.e(AboutActivity.class.getName(),"Couldn't find package information in PackageManager",e); } return null; }
Example 63
From project DrmLicenseService, under directory /src/com/sonyericsson/android/drm/drmlicenseservice/.
Source file: HttpClient.java

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 64
From project droid-comic-viewer, under directory /src/net/robotmedia/acv/ui/settings/mobile/.
Source file: AboutSettingsActivity.java

@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 65
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 66
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 67
From project droidparts, under directory /extra/src/org/droidparts/util/.
Source file: AppUtils.java

public String getVersionName(){ String verName="?"; try { verName=ctx.getPackageManager().getPackageInfo(ctx.getPackageName(),0).versionName; } catch ( NameNotFoundException e) { L.e(e); } return verName; }
Example 68
/** * 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 E12Planner, under directory /src/com/neoware/europlanner/.
Source file: PlannerHomeActivity.java

@Override public boolean onOptionsItemSelected(MenuItem item){ switch (item.getItemId()) { case R.id.menu_about: try { AlertDialog alertDialog=new AlertDialog.Builder(this).create(); alertDialog.setTitle(R.string.aboutMenu); alertDialog.setMessage("v" + getPackageManager().getPackageInfo(getPackageName(),0).versionName + "\n\n"+ getResources().getString(R.string.aboutText)); alertDialog.setButton(getResources().getString(android.R.string.ok),new DialogInterface.OnClickListener(){ @Override public void onClick( DialogInterface dialog, int which){ } } ); alertDialog.show(); } catch ( NameNotFoundException ex) { } return true; default : return super.onOptionsItemSelected(item); } }
Example 70
From project Ebento, under directory /src/mobisocial/bento/ebento/util/.
Source file: InitialHelper.java

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 71
From project ElectricSleep, under directory /src/com/androsz/electricsleepbeta/app/.
Source file: HostActivity.java

@Override public boolean onOptionsItemSelected(final MenuItem item){ switch (item.getItemId()) { case android.R.id.home: finish(); return (true); case R.id.menu_item_tutorial: startActivity(new Intent(this,WelcomeTutorialWizardActivity.class)); break; case R.id.menu_item_calibrate: startActivity(new Intent(this,CalibrationWizardActivity.class)); break; case R.id.menu_item_settings: startActivity(new Intent(this,SettingsActivity.class)); break; case R.id.menu_item_report: String versionName="???"; try { versionName=getPackageManager().getPackageInfo(this.getPackageName(),PackageManager.GET_META_DATA).versionName; } catch (NameNotFoundException e) { this.trackEvent("Retrieving VersionName failed for HostActivity.",1); break; } final Intent emailIntent=new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{getString(R.string.developer_email_address)}); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,getString(R.string.email_developer_subject,versionName)); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,getString(R.string.developer_email_body)); startActivity(Intent.createChooser(emailIntent,getString(R.string.title_report))); break; } return super.onOptionsItemSelected(item); }
Example 72
From project eoit, under directory /EOIT/src/fr/eoit/activity/.
Source file: GoogleAnalyticsActivity.java

@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 73
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 74
From project facebook-android-sdk, under directory /facebook/src/com/facebook/android/.
Source file: Facebook.java

/** * 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 75
/** * Get the SwiFTP version from the manifest. * @return The version as a String. */ public static String getVersion(){ String packageName=Globals.getContext().getPackageName(); try { return Globals.getContext().getPackageManager().getPackageInfo(packageName,0).versionName; } catch ( NameNotFoundException e) { myLog.l(Log.ERROR,"NameNotFoundException looking up SwiFTP version"); return null; } }
Example 76
From project filemanager, under directory /FileManager/src/org/openintents/filemanager/.
Source file: FileManagerProvider.java

private void getMimeTypes(){ Context ctx=getContext(); MimeTypeParser mtp=null; try { mtp=new MimeTypeParser(ctx,ctx.getPackageName()); } catch ( NameNotFoundException e) { } XmlResourceParser in=getContext().getResources().getXml(R.xml.mimetypes); try { mMimeTypes=mtp.fromXmlResource(in); } catch ( XmlPullParserException e) { Log.e(TAG,"PreselectedChannelsActivity: XmlPullParserException",e); throw new RuntimeException("PreselectedChannelsActivity: XmlPullParserException"); } catch ( IOException e) { Log.e(TAG,"PreselectedChannelsActivity: IOException",e); throw new RuntimeException("PreselectedChannelsActivity: IOException"); } }
Example 77
From project FlickrCity, under directory /src/com/FlickrCity/FlickrCityAndroid/Activities/.
Source file: MapViewerActivity.java

private Dialog aboutDialog(){ String versionName; try { versionName=getPackageManager().getPackageInfo(getPackageName(),0).versionName; } catch ( NameNotFoundException e) { versionName="0"; } SpannableString s=new SpannableString(getText(R.string.about_text).toString().replace("#",versionName)); Linkify.addLinks(s,Linkify.WEB_URLS); LinearLayout information=(LinearLayout)getLayoutInflater().inflate(R.layout.about,null); TextView about_text_view=(TextView)information.findViewById(R.id.aboutTextView); about_text_view.setText(s); about_text_view.setMovementMethod(LinkMovementMethod.getInstance()); Dialog dialog=new AlertDialog.Builder(this).setIcon(R.drawable.flickrcity_launcher_48).setTitle(R.string.app_name).setView(information).setPositiveButton(android.R.string.ok,null).create(); return dialog; }
Example 78
From project Gaggle, under directory /src/com/geeksville/location/.
Source file: LeonardoLiveWriter.java

/** * 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 79
@Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); context=getApplicationContext(); AndroidGL20 gl20; if (isHoneycombOrLater() || !AndroidGL20Native.available) { gl20=new AndroidGL20(); } else { gl20=new AndroidGL20Native(); } viewLayout=new AndroidLayoutView(this); gameView=new GameViewGL(gl20,this,context); viewLayout.addView(gameView); if (isHoneycombOrLater()) { int flagHardwareAccelerated=0x1000000; getWindow().setFlags(flagHardwareAccelerated,flagHardwareAccelerated); } getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); LayoutParams params=new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT); getWindow().setContentView(viewLayout,params); if (usePortraitOrientation()) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } try { ActivityInfo info=this.getPackageManager().getActivityInfo(new ComponentName(context,this.getPackageName() + "." + this.getLocalClassName()),0); if ((info.configChanges & REQUIRED_CONFIG_CHANGES) != REQUIRED_CONFIG_CHANGES) { new AlertDialog.Builder(this).setMessage("Unable to guarantee application will handle configuration changes. " + "Please add the following line to the Activity manifest: " + " android:configChanges=\"keyboardHidden|orientation\"").show(); } } catch ( NameNotFoundException e) { Log.w("playn","Cannot access game AndroidManifest.xml file."); } }
Example 80
From project GCM-Demo, under directory /gcm/gcm-client/src/com/google/android/gcm/.
Source file: GCMRegistrar.java

/** * Checks if the device has the proper dependencies installed. <p> This method should be called when the application starts to verify that the device supports GCM. * @param context application context. * @throws UnsupportedOperationException if the device does not support GCM. */ public static void checkDevice(Context context){ int version=Build.VERSION.SDK_INT; if (version < 8) { throw new UnsupportedOperationException("Device must be at least " + "API Level 8 (instead of " + version + ")"); } PackageManager packageManager=context.getPackageManager(); try { packageManager.getPackageInfo(GSF_PACKAGE,0); } catch ( NameNotFoundException e) { throw new UnsupportedOperationException("Device does not have package " + GSF_PACKAGE); } }
Example 81
From project gddsched2, under directory /trunk/android/src/com/google/android/apps/iosched2/service/.
Source file: SyncService.java

/** * 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 82
From project Gibberbot, under directory /src/info/guardianproject/otr/app/im/app/.
Source file: BrandingResources.java

/** * Creates a new BrandingResource of a specific plug-in. The resources will be retrieved from the plug-in package. * @param context The current application context. * @param pluginInfo The info about the plug-in. * @param defaultRes The default branding resources. If the resource is notfound in the plug-in, the default resource will be returned. */ public BrandingResources(Context context,ImPluginInfo pluginInfo,BrandingResources defaultRes){ mDefaultRes=defaultRes; PackageManager pm=context.getPackageManager(); try { mPackageRes=pm.getResourcesForApplication(pluginInfo.mPackageName); } catch ( NameNotFoundException e) { Log.e(TAG,"Can not load resources from package: " + pluginInfo.mPackageName); } ClassLoader classLoader=context.getClassLoader(); try { Class cls=classLoader.loadClass(pluginInfo.mClassName); Method m=cls.getMethod("onBind",Intent.class); ImPlugin plugin=(ImPlugin)m.invoke(cls.newInstance(),new Object[]{null}); mResMapping=plugin.getResourceMap(); mSmileyIcons=plugin.getSmileyIconIds(); } catch ( ClassNotFoundException e) { Log.e(TAG,"Failed load the plugin resource map",e); } catch ( IllegalAccessException e) { Log.e(TAG,"Failed load the plugin resource map",e); } catch ( InstantiationException e) { Log.e(TAG,"Failed load the plugin resource map",e); } catch ( SecurityException e) { Log.e(TAG,"Failed load the plugin resource map",e); } catch ( NoSuchMethodException e) { Log.e(TAG,"Failed load the plugin resource map",e); } catch ( IllegalArgumentException e) { Log.e(TAG,"Failed load the plugin resource map",e); } catch ( InvocationTargetException e) { Log.e(TAG,"Failed load the plugin resource map",e); } }
Example 83
From project Gingerbread-Keyboard, under directory /src/com/android/inputmethod/latin/.
Source file: LatinIMEDebugSettings.java

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 84
From project gobandroid, under directory /src/org/ligi/gobandroid_hd/.
Source file: GobandroidApp.java

public String getAppVersion(){ try { return getPackageManager().getPackageInfo(this.getPackageName(),0).versionName; } catch ( NameNotFoundException e) { Log.w("cannot determine app version - that's strange but not critical"); return "vX.Y"; } }
Example 85
From project google-voice-tasker-plugin, under directory /tests/src/com/yourcompany/yoursetting/test/.
Source file: ManifestTest.java

/** * Tests that the plug-in targets at least the same SDK as Locale. */ public void testTargetSdk(){ try { final Context localeContext=getContext().createPackageContext(getHostPackage(getContext().getPackageManager()),0); assertTrue(getContext().getApplicationInfo().targetSdkVersion >= localeContext.getApplicationInfo().targetSdkVersion); } catch ( final NameNotFoundException e) { throw new RuntimeException(e); } }
Example 86
From project GradeCalculator-Android, under directory /GradeCalculator/src/com/jetheis/android/grades/billing/.
Source file: Security.java

private static String getUnlockKeyForDevice(Context context){ String deviceId=Secure.getString(context.getContentResolver(),Secure.ANDROID_ID); String packageName=context.getPackageName(); String versionName; try { versionName=context.getPackageManager().getPackageInfo(context.getPackageName(),0).versionName; } catch ( NameNotFoundException e) { throw new RuntimeException("Encoding error",e); } String keyResourceString=context.getString(R.string.key_part); return versionName + deviceId + packageName+ keyResourceString+ KEY_PART; }
Example 87
From project GreenDroid, under directory /GreenDroid/src/greendroid/app/.
Source file: GDActivity.java

public void onPostContentChanged(){ boolean titleSet=false; final Intent intent=getIntent(); if (intent != null) { String title=intent.getStringExtra(ActionBarActivity.GD_ACTION_BAR_TITLE); if (title != null) { titleSet=true; setTitle(title); } } if (!titleSet) { try { final ActivityInfo activityInfo=getPackageManager().getActivityInfo(getComponentName(),0); if (activityInfo.labelRes != 0) { setTitle(activityInfo.labelRes); } } catch ( NameNotFoundException e) { } } final int visibility=intent.getIntExtra(ActionBarActivity.GD_ACTION_BAR_VISIBILITY,View.VISIBLE); getActionBar().setVisibility(visibility); }