Android Auto / GridItem / Showing custom Image?

103 views Asked by At

I'm currently creating an Android Auto Application, and for the Grid-View that is to be used, the user is able to store own images during runtime in the smartphone-view.

Now, when displaying these entries In Android Auto through the GridItemBuilder i'm trying to reuse the image, that has been stored by the user. CarIconBuilder offers the possibility to use IconCompat, which im trying to do. But running these lines of code:

 public Template onGetTemplate() {
    ...
    String fileName = carContext.getCacheDir() + "/state_img_" + state.optLong("id") + ".png";
    File imageFile = new File(fileName);

    if (imageFile.exists()){
       IconCompat icon = IconCompat.createWithContentUri(Uri.fromFile(imageFile));
       gib.setImage(new CarIcon.Builder(icon).build(), GridItem.IMAGE_TYPE_ICON);
    }else{
       //TODO: Handle No-Image-Case.
    }

    gib.setTitle(state.optString("name"));
    gib.setLoading(false);
    ...
}

returns the builder-exception:

java.lang.IllegalArgumentException: Unsupported URI scheme for: Icon(typ=URI uri=file:///data/user/0/my.namespace.appname/cache/state_img_1698487391260.png)

The file is detected existing, and displaying it in the mobile-view through ImageView also works flawless. Not sure, where the issue is with Car-Icon-Builder here, any idea?

1

There are 1 answers

0
dognose On

After trying a bunch of different things, finally creating a bitmap first is working now:

if (imageFile.exists()){
    Bitmap bmp = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
    IconCompat icon = IconCompat.createWithBitmap(bmp);
    gib.setImage(new CarIcon.Builder(icon).build());
}else{
    //TODO: Handle No-Image-Case.
}