List of usage examples for android.content.pm PackageManager.NameNotFoundException getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.typingsolutions.passwordmanager.fragments.AboutFragment.java
@Nullable @Override/*from w w w .j a v a 2s . c o m*/ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = inflater.inflate(R.layout.about_layout, container, false); TextView textView = (TextView) root.findViewById(R.id.aboutlayout_textview_version); Button button = (Button) root.findViewById(R.id.aboutlayout_button_license); button.setOnClickListener(new ShowLicensesClickCallback(getSupportActivity())); try { String packageName = getActivity().getPackageName(); PackageInfo info = getActivity().getPackageManager().getPackageInfo(packageName, 0); textView.setText(textView.getText().toString().replace("{Major}", info.versionName)); textView.setText( textView.getText().toString().replace("{Release}", Integer.toString(info.versionCode))); } catch (PackageManager.NameNotFoundException e) { Log.e(getClass().getSimpleName(), String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage())); } return root; }
From source file:org.tomahawk.tomahawk_android.fragments.FakePreferenceFragment.java
/** * Called, when this {@link FakePreferenceFragment}'s {@link View} has been created *///from w w w . j av a 2 s . c om @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // Fetch our SharedPreferences from the PreferenceManager mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); mSharedPreferences.registerOnSharedPreferenceChangeListener(this); // Set up the set of FakePreferences to be shown in this Fragment mFakePreferenceGroups = new ArrayList<FakePreferenceGroup>(); FakePreferenceGroup prefGroup = new FakePreferenceGroup(getString(R.string.fakepreference_accounts_header)); prefGroup.addFakePreference( new FakePreferenceGroup.FakePreference(FakePreferenceGroup.FAKEPREFERENCE_TYPE_AUTH, TomahawkApp.PLUGINNAME_HATCHET, getString(R.string.hatchet_pretty_name), getString(R.string.fakepreference_hatchetlogin_summary_string), R.drawable.hatchet_icon)); prefGroup.addFakePreference( new FakePreferenceGroup.FakePreference(FakePreferenceGroup.FAKEPREFERENCE_TYPE_AUTH, TomahawkApp.PLUGINNAME_SPOTIFY, getString(R.string.spotify_pretty_name), getString(R.string.fakepreference_spotifylogin_summary_string), R.drawable.spotify_icon)); for (ScriptResolver scriptResolver : PipeLine.getInstance().getScriptResolvers()) { prefGroup.addFakePreference( new FakePreferenceGroup.FakePreference(FakePreferenceGroup.FAKEPREFERENCE_TYPE_CONFIG, scriptResolver.getId(), scriptResolver.getName(), scriptResolver.getDescription())); } mFakePreferenceGroups.add(prefGroup); prefGroup = new FakePreferenceGroup(getString(R.string.fakepreference_playback_header)); prefGroup.addFakePreference( new FakePreferenceGroup.FakePreference(FakePreferenceGroup.FAKEPREFERENCE_TYPE_CHECKBOX, FAKEPREFERENCEFRAGMENT_ID_PLUGINTOPLAY, FAKEPREFERENCEFRAGMENT_KEY_PLUGINTOPLAY, getString(R.string.fakepreference_plugintoplay_title_string), getString(R.string.fakepreference_plugintoplay_summary_string))); prefGroup.addFakePreference( new FakePreferenceGroup.FakePreference(FakePreferenceGroup.FAKEPREFERENCE_TYPE_CHECKBOX, FAKEPREFERENCEFRAGMENT_ID_SCROBBLEEVERYTHING, FAKEPREFERENCEFRAGMENT_KEY_SCROBBLEEVERYTHING, getString(R.string.fakepreference_scrobble_title_string), getString(R.string.fakepreference_scrobble_summary_string))); prefGroup.addFakePreference(new FakePreferenceGroup.FakePreference( FakePreferenceGroup.FAKEPREFERENCE_TYPE_SPINNER, FAKEPREFERENCEFRAGMENT_ID_PREFBITRATE, FAKEPREFERENCEFRAGMENT_KEY_PREFBITRATE, getString(R.string.fakepreference_bitrate_title_string), getString(R.string.fakepreference_bitrate_summary_string))); mFakePreferenceGroups.add(prefGroup); prefGroup = new FakePreferenceGroup(getString(R.string.fakepreference_info_header)); String versionName = ""; try { if (getActivity().getPackageManager() != null) { PackageInfo packageInfo = getActivity().getPackageManager() .getPackageInfo(getActivity().getPackageName(), 0); versionName = packageInfo.versionName; } } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "onViewCreated: " + e.getClass() + ": " + e.getLocalizedMessage()); } prefGroup.addFakePreference( new FakePreferenceGroup.FakePreference(FakePreferenceGroup.FAKEPREFERENCE_TYPE_PLAIN, FAKEPREFERENCEFRAGMENT_ID_APPVERSION, FAKEPREFERENCEFRAGMENT_KEY_APPVERSION, getString(R.string.fakepreference_appversion_title_string), versionName)); mFakePreferenceGroups.add(prefGroup); // Now we can push the complete set of FakePreferences into our FakePreferencesAdapter, // so that it can provide our ListView with the correct Views. FakePreferencesAdapter fakePreferencesAdapter = new FakePreferencesAdapter(getActivity(), getActivity().getLayoutInflater(), mFakePreferenceGroups); setListAdapter(fakePreferencesAdapter); getListView().setOnItemClickListener(this); }