use of android.content.pm.PackageManager.NameNotFoundException in project cw-omnibus by commonsguy.
the class SuggestionsAdapter method getTheDrawable.
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);
}
use of android.content.pm.PackageManager.NameNotFoundException in project packer-ng-plugin by mcxiaoke.
the class MainActivity method addMetaDataSection.
private void addMetaDataSection() {
final PackageManager pm = getPackageManager();
final String packageName = getPackageName();
try {
final ApplicationInfo info = pm.getApplicationInfo(packageName, PackageManager.GET_SIGNATURES | PackageManager.GET_META_DATA);
final Bundle bundle = info.metaData;
final StringBuilder builder = new StringBuilder();
builder.append("[MetaData]\n");
if (bundle != null) {
final Set<String> keySet = bundle.keySet();
for (final String key : keySet) {
builder.append(key).append("=").append(bundle.get(key)).append("\n");
}
}
addSection(builder.toString());
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
use of android.content.pm.PackageManager.NameNotFoundException in project AndroidTraining by mixi-inc.
the class SuggestionsAdapter method getTheDrawable.
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);
}
use of android.content.pm.PackageManager.NameNotFoundException in project AndroidTraining by mixi-inc.
the class SuggestionsAdapter method getActivityIcon.
/**
* Gets the activity or application icon for an activity.
*
* @param component Name of an activity.
* @return A drawable, or {@code null} if neither the acitivy or the application
* have an icon set.
*/
private Drawable getActivityIcon(ComponentName component) {
PackageManager pm = mContext.getPackageManager();
final ActivityInfo activityInfo;
try {
activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
} catch (NameNotFoundException ex) {
Log.w(LOG_TAG, ex.toString());
return null;
}
int iconId = activityInfo.getIconResource();
if (iconId == 0)
return null;
String pkg = component.getPackageName();
Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
if (drawable == null) {
Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString());
return null;
}
return drawable;
}
use of android.content.pm.PackageManager.NameNotFoundException in project Inscription by MartinvanZ.
the class ChangeLogDialog method getHTML.
//Returns change log in HTML format
public String getHTML() {
//TODO: Remove duplicate code with the method show()
//Get resources
final String packageName = mContext.getPackageName();
final Resources resources;
try {
resources = mContext.getPackageManager().getResourcesForApplication(packageName);
} catch (NameNotFoundException ignored) {
return "";
}
//Create HTML change log
return getHTMLChangelog(R.xml.changelog, resources, 0);
}
Aggregations