Search in sources :

Example 31 with NotFoundException

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);
}
Also used : InputStream(java.io.InputStream) SettingNotFoundException(android.provider.Settings.SettingNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Resources(android.content.res.Resources)

Example 32 with NotFoundException

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);
    }
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) Builder(com.google.android.gms.cast.Cast.CastOptions.Builder) NotFoundException(android.content.res.Resources.NotFoundException) FetchBitmapTask(com.google.android.libraries.cast.companionlibrary.utils.FetchBitmapTask) Uri(android.net.Uri) Bitmap(android.graphics.Bitmap) MediaInfo(com.google.android.gms.cast.MediaInfo) MediaMetadata(com.google.android.gms.cast.MediaMetadata) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException)

Example 33 with NotFoundException

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();
    }
}
Also used : PackageInfo(android.content.pm.PackageInfo) ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException)

Example 34 with NotFoundException

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;
    }
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) Resources(android.content.res.Resources)

Example 35 with NotFoundException

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));
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) AttrResourceValue(com.android.ide.common.rendering.api.AttrResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) NotFoundException(android.content.res.Resources.NotFoundException) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue)

Aggregations

NotFoundException (android.content.res.Resources.NotFoundException)165 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)49 Resources (android.content.res.Resources)47 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 FileNotFoundException (java.io.FileNotFoundException)34 IOException (java.io.IOException)34 ApplicationInfo (android.content.pm.ApplicationInfo)31 File (java.io.File)30 InputStream (java.io.InputStream)28 FileInputStream (java.io.FileInputStream)20 Drawable (android.graphics.drawable.Drawable)19 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)16 Nullable (android.annotation.Nullable)15 XmlResourceParser (android.content.res.XmlResourceParser)12 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)12 ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)12 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)12 NonNull (android.annotation.NonNull)10 ColorDrawable (android.graphics.drawable.ColorDrawable)10 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)8