Skip to content

Commit

Permalink
Merge pull request #30 from tverona1/misc
Browse files Browse the repository at this point in the history
Fix loading VectorDrawable icons
  • Loading branch information
tverona1 authored Dec 15, 2019
2 parents dd9d94f + f0838f5 commit c74cfd0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
28 changes: 22 additions & 6 deletions Assets/Plugins/Android/AppInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.Canvas;
import android.graphics.Color;
import java.util.List;
import java.util.LinkedList;
Expand Down Expand Up @@ -119,12 +121,26 @@ public boolean is2DApp(int i)
}

public byte[] getIcon(int i) {
BitmapDrawable icon = (BitmapDrawable)this.getPackageManager().getApplicationIcon(installedApps.get(i).app);
Bitmap bmp = icon.getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
return byteArray;
try {
Drawable drawable = this.getPackageManager().getApplicationIcon(installedApps.get(i).app);
Bitmap bmp = null;
if (drawable instanceof BitmapDrawable) {
bmp = ((BitmapDrawable)drawable).getBitmap();
} else {
bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bmp);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
return byteArray;
} catch (Exception e) {
e.printStackTrace();
}

return null;
}

public boolean hasUsageStatsPermissions() {
Expand Down
6 changes: 6 additions & 0 deletions Assets/Scripts/AppEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ public async Task LoadIcon()

Texture2D texture = null;

if (null == image)
{
Debug.LogFormat("Error loading icon: Path: {0}, Index: {1}", this.externalIconPath, this.installedApkIndex);
return;
}

// Set the icon image
if (imageWidth == 0 || imageHeight == 0)
{
Expand Down

0 comments on commit c74cfd0

Please sign in to comment.