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);
このコードは利用可能なすべてのアプリケーションを表示しますが、結果に取り組みたいと思います。あなたが持っているすべての行com.android.*で、それは私がカットしたい部分です.
問題は、substring(10)たとえば使用しようとしたときに結果が変わらないことです。
私はそのように試してみましたが、Logで部分文字列が成功しましたが、画面に表示すると、すべてのボタンを含む別のレイアウトが表示されます。このコードでほとんど取得できます。画面に表示したいものをLogで表示しますが、ログで正しい結果が得られましたが、理由がわかりません
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);