Created
August 5, 2016 17:53
-
-
Save JohnZavyn/af6ffc3d58443311c4a3bc8eba949932 to your computer and use it in GitHub Desktop.
Extract the icon from an APK file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.dongliu.apk.parser.ApkParser; | |
import net.dongliu.apk.parser.bean.Icon; | |
import org.apache.log4j.Logger; | |
import java.io.*; | |
/** Services for managing APK (Adroid Application Package) objects. */ | |
public class ApkService | |
{ | |
/** The {@link Logger}. */ | |
private static final Logger LOGGER = Logger.getLogger(ApkService.class); | |
/** | |
* Extract the icon from an APK file. | |
* | |
* @param apkParser the {@link ApkParser} | |
* | |
* @return the icon temp {@link File} | |
*/ | |
public File saveIcon(ApkParser apkParser) | |
{ | |
OutputStream out = null; | |
File file = null; | |
try | |
{ | |
final Icon iconFile = apkParser.getIconFile(); | |
String iconPath = iconFile.getPath(); | |
String extension = iconPath.substring(iconPath.lastIndexOf('.')); | |
file = File.createTempFile("icon", extension); | |
out = new FileOutputStream(file); | |
out.write(iconFile.getData()); | |
out.flush(); | |
} | |
catch (Exception e) | |
{ | |
throw new IllegalStateException("Problem extracting icon", e); | |
} | |
finally | |
{ | |
if (out != null) | |
{ | |
try | |
{ | |
out.close(); | |
} | |
catch (IOException e) | |
{ | |
LOGGER.error(e); | |
} | |
} | |
} | |
return file; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment