从名称

时间:2017-12-15 11:54:57

标签: java android android-spinner android-applicationinfo package-name

我正在尝试将所有已安装的程序列表放入Spinner。它仅显示packageInfo.packageName,但所选项目应在微调器下方的packageInfo.sourceDir上显示MD5SHA1TextView校验和。

据我所知,这些行将信息存储在字典中。

    final PackageManager pm = getPackageManager();
    //get a list of installed apps.
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

如何在选择微调器项目时检索所有信息。

public class DisplayClass extends Activity implements AdapterView.OnItemSelectedListener{
     final PackageManager pm = getPackageManager();
        //get a list of installed apps.
     List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.display_layout);


        //String tv;
        TextView tv = findViewById(R.id.textView3);
        tv.setMovementMethod( new ScrollingMovementMethod());
        ArrayList<String> progArray = new ArrayList<String>();
        Spinner spinner = findViewById(R.id.spinner);

        for (ApplicationInfo packageInfo : packages) {
            //Log.d(TAG, "Installed package :" + packageInfo.packageName);
            //Log.d(TAG, "Source dir : " + packageInfo.sourceDir);
            String stringName = ("Package : " + packageInfo);
            progArray.add(stringName);
            //Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
        }
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, progArray);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Apply the adapter to the spinner
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(this);
    }

    @Override
    public <T extends View> T findViewById(int id) {
        return super.findViewById(id);
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {


        Spinner mySpinner=(Spinner) findViewById(R.id.spinner);
        TextView tv = findViewById(R.id.selectedItem);
        String text = mySpinner.getSelectedItem().toString();
        //tv.append("Package : \n" + packageInfo.packageName+'\n');
        //tv.append("Dir : \n" + packageInfo.sourceDir+'\n');
        //File file = new File(packageInfo.sourceDir);
        //String md5 = MD5.calculateMD5(file);
        //String sha1 = SHA1.calculateSHA1(file);
        //tv.setText("MD5 : \n" +md5 +"\n " );
        //tv.append("SHA1 : \n" +sha1 +"\n \n" );

        tv.setText(text);
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }
}

0 个答案:

没有答案