From 964cf03653fb28f49c373421d472ae30b641b546 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 30 Nov 2018 19:23:35 +0100 Subject: catch npe while detecting apk names --- .../de/pixart/messenger/persistance/FileBackend.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 092feabe2..6ea506692 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -1023,20 +1023,25 @@ public class FileBackend { private String getAPK (File file, Context context) { String APKName; - //final Drawable icon; final PackageManager pm = context.getPackageManager(); final PackageInfo pi = pm.getPackageArchiveInfo(file.toString(), 0); - pi.applicationInfo.sourceDir = file.toString(); - pi.applicationInfo.publicSourceDir = file.toString(); - //icon = pi.applicationInfo.loadIcon(pm); - final String AppName = (String) pi.applicationInfo.loadLabel(pm); - final String AppVersion = pi.versionName; + String AppName; + String AppVersion; + try { + pi.applicationInfo.sourceDir = file.toString(); + pi.applicationInfo.publicSourceDir = file.toString(); + AppName = (String) pi.applicationInfo.loadLabel(pm); + AppVersion = pi.versionName; + } catch (Exception e) { + e.printStackTrace(); + AppName = String.valueOf(R.string.apk); + AppVersion = "0"; + } Log.d(Config.LOGTAG, "APK name: " + AppName); APKName = " (" + AppName + " " + AppVersion + ")"; try { byte[] data = APKName.getBytes("UTF-8"); APKName = Base64.encodeToString(data, Base64.DEFAULT); - } catch (UnsupportedEncodingException e) { APKName = ""; e.printStackTrace(); -- cgit v1.2.3