use of android.content.res.Resources.NotFoundException in project android_frameworks_base by AOSPA.
the class PackageManagerTests method getInstallablePackage.
Uri getInstallablePackage(int fileResId, File outFile) {
Resources res = mContext.getResources();
InputStream is = null;
try {
is = res.openRawResource(fileResId);
} catch (NotFoundException e) {
failStr("Failed to load resource with id: " + fileResId);
}
FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
assertTrue(FileUtils.copyToFile(is, outFile));
FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
return Uri.fromFile(outFile);
}
use of android.content.res.Resources.NotFoundException in project Shuttle by timusus.
the class VideoCastManager method updateMediaSessionMetadata.
/*
* On ICS and JB, lock screen metadata is one liner: Title - Album Artist - Album. On KitKat, it
* has two lines: Title , Album Artist - Album
*/
private void updateMediaSessionMetadata() {
if ((mMediaSessionCompat == null) || !isFeatureEnabled(CastConfiguration.FEATURE_LOCKSCREEN)) {
return;
}
try {
MediaInfo info = getRemoteMediaInformation();
if (info == null) {
return;
}
final MediaMetadata mm = info.getMetadata();
MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
MediaMetadataCompat metadata = newBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, mm.getString(MediaMetadata.KEY_TITLE)).putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, mContext.getResources().getString(R.string.ccl_casting_to_device, getDeviceName())).putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, mm.getString(MediaMetadata.KEY_TITLE)).putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, mm.getString(MediaMetadata.KEY_SUBTITLE)).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, info.getStreamDuration()).build();
mMediaSessionCompat.setMetadata(metadata);
Uri iconUri = mm.hasImages() ? mm.getImages().get(0).getUrl() : null;
if (iconUri == null) {
Bitmap bm = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.album_art_placeholder);
mMediaSessionCompat.setMetadata(newBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bm).build());
} else {
if (mMediaSessionIconFetchTask != null) {
mMediaSessionIconFetchTask.cancel(true);
}
mMediaSessionIconFetchTask = new FetchBitmapTask() {
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null && mMediaSessionCompat != null) {
MediaMetadataCompat currentMetadata = mMediaSessionCompat.getController().getMetadata();
MediaMetadataCompat.Builder newBuilder = currentMetadata == null ? new MediaMetadataCompat.Builder() : new MediaMetadataCompat.Builder(currentMetadata);
mMediaSessionCompat.setMetadata(newBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, bitmap).build());
}
mMediaSessionIconFetchTask = null;
}
};
mMediaSessionIconFetchTask.execute(iconUri);
}
} catch (NotFoundException e) {
LOGE(TAG, "Failed to update Media Session due to resource not found", e);
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "Failed to update Media Session due to network issues", e);
}
}
use of android.content.res.Resources.NotFoundException in project platform_frameworks_base by android.
the class AndroidPackageInfoFetcher method getStatements.
/**
* Returns all statements that the specified package makes in its AndroidManifest.xml.
*
* @throws NameNotFoundException if the app is not installed on the device.
*/
public List<String> getStatements(String packageName) throws NameNotFoundException {
PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);
ApplicationInfo appInfo = packageInfo.applicationInfo;
if (appInfo.metaData == null) {
return Collections.<String>emptyList();
}
int tokenResourceId = appInfo.metaData.getInt(ASSOCIATED_ASSETS_KEY);
if (tokenResourceId == 0) {
return Collections.<String>emptyList();
}
try {
return Arrays.asList(mContext.getPackageManager().getResourcesForApplication(packageName).getStringArray(tokenResourceId));
} catch (NotFoundException e) {
return Collections.<String>emptyList();
}
}
use of android.content.res.Resources.NotFoundException in project platform_frameworks_base by android.
the class ApduServiceInfo method loadBanner.
public Drawable loadBanner(PackageManager pm) {
Resources res;
try {
res = pm.getResourcesForApplication(mService.serviceInfo.packageName);
Drawable banner = res.getDrawable(mBannerResourceId);
return banner;
} catch (NotFoundException e) {
Log.e(TAG, "Could not load banner.");
return null;
} catch (NameNotFoundException e) {
Log.e(TAG, "Could not load banner.");
return null;
}
}
use of android.content.res.Resources.NotFoundException in project platform_frameworks_base by android.
the class BridgeTypedArray method getTextArray.
/**
* Retrieve the CharSequence[] for the attribute at <var>index</var>.
* This gets the resource ID of the selected attribute, and uses
* {@link Resources#getTextArray Resources.getTextArray} of the owning
* Resources object to retrieve its String[].
*
* @param index Index of attribute to retrieve.
*
* @return CharSequence[] for the attribute, or null if not defined.
*/
@Override
public CharSequence[] getTextArray(int index) {
if (!hasValue(index)) {
return null;
}
ResourceValue resVal = mResourceData[index];
if (resVal instanceof ArrayResourceValue) {
ArrayResourceValue array = (ArrayResourceValue) resVal;
int count = array.getElementCount();
return count >= 0 ? Resources_Delegate.fillValues(mBridgeResources, array, new CharSequence[count]) : null;
}
int id = getResourceId(index, 0);
String resIdMessage = id > 0 ? " (resource id 0x" + Integer.toHexString(id) + ')' : "";
throw new NotFoundException(String.format("%1$s in %2$s%3$s is not a valid array resource.", resVal.getValue(), mNames[index], resIdMessage));
}
Aggregations