final Intent mainIntent=new Intent(Intent.ACTION_MAIN,null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER) ;
final PackageManager pm = getApplicationContext().getPackageManager();
ArrayList<ResolveInfo> listP= (ArrayList<ResolveInfo>) pm.queryIntentActivities( mainIntent, 0);
//Drawable iconApp = resolveInfo.activityInfo.loadIcon(getPackageManager());
ApplicationAdapter adapter = new ApplicationAdapter(this, listP);
adapter.addListener(this);
ListView list = (ListView)findViewById(R.id.list);
list.setAdapter(adapter);
This code displays all applications available but I would like to work on the result. On every line you've got com.android.*
and it's that part I would like to cut.
The problem is when I tried to use substring(10)
for example it doesn't change the result.
i tried that way and with Log i success the substring but when i display it on the screen it just show me another layout with all his buttons i almost get it with this code i display with Log exactly what i want to put on screens but there is just a black board while i got the right result with the Log i can't see the reason
public void onCreatebis() {
setContentView(R.layout.main);
final Intent mainIntent=new Intent(Intent.ACTION_MAIN,null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER) ;
final PackageManager pm = getApplicationContext().getPackageManager();
ArrayList<ResolveInfo> listP= (ArrayList<ResolveInfo>) pm.queryIntentActivities( mainIntent, 0);
final int trimLength = "com.android.".length();
ArrayList<String> maliste = new ArrayList();
int size=listP.size();
size=maliste.size();
//String []maliste=new String[listP.size()];
// Loop over each item.
for (ResolveInfo info : listP) {
// Get the (full, qualified) package name.
String packag = info.activityInfo.applicationInfo.packageName;
// Now, trim it with substring and the trim length.
String trimmed = packag.substring(trimLength);
for(int i=0;i<maliste.size();i++){
maliste.set(i, trimmed);
}
Log.v("trimmed", trimmed);
// [ do whatever you want with the trimmed name ]
}
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, maliste);
ListView list = (ListView)findViewById(R.id.list);
list.setAdapter(adapter2);