I am building a root app allowing to debloat apk files from system/app and system/priv app. I have a ListView that takes the content of both dirs and filters them against a string array that I built (not all apps can be debloated). It feeds into a list with multiple choice mode. Now, what I can't manage is how to display apk files with their icons. I am using a simple adapter for now. But I can switch to base adapter. What I need is a way to add the app icons into the Image View. I am not using the package manager to generate the list, for several reasons I need it to be the actual apk files that are displayed. Can someone please help me with a way to make an apk file display with it's icon? Like in root explorer f.e.? This is the main part of code that takes care of the list for now:
public class MainActivity extends ListActivity
implements View.OnClickListener,
AdapterView.OnItemSelectedListener{
private List<String> fileList = new ArrayList<String>();
Button debloat;
ListView appList;
File app = new File("/system/app");
File privApp = new File("/system/priv-app");
ArrayAdapter<String> directoryList;
BufferedWriter debloatBW;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
Runtime.getRuntime().exec("su");
} catch (IOException e) {
e.printStackTrace();
}
setContentView(R.layout.activity_main);
debloat = (Button) findViewById(R.id.button);
debloat.setOnClickListener(this);
appList = getListView();
File[] files = app.listFiles();
File[] files1 = privApp.listFiles();
List<String> relevantApps =
Arrays.asList(getResources().getStringArray(R.array.include_apk));
fileList.clear();
for (File file : files){
if (file.isFile()
&& file.getPath().endsWith(".apk")
&& relevantApps.contains(file.getName().toString()))
{
fileList.add(file.getName());
}
}
for (File file1 : files1) {
if (file1.isFile()
&& file1.getPath().endsWith(".apk")
&& relevantApps.contains(file1.getName().toString()))
{
fileList.add(file1.getName());
}
}
directoryList = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, fileList);
appList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
appList.setAdapter(directoryList);
}
Thank you for any advice you might have! Cheers!