0

I have a problem with disable application through package manager function disable/enable. In android terminal is all corect, but in this application not. However " Runtime.getRuntime().exec("su"); " functioning normally and carrying out his activity.

public class AppInfoAdapter extends BaseAdapter {
private Context aContext;
private List<ApplicationInfo> aListAppInfo;
private PackageManager aPackManager;
private CheckBox chAppStat ;






public AppInfoAdapter(Context c, List<ApplicationInfo> list, PackageManager pm) {
    aContext = c;
    aListAppInfo = list;
    aPackManager = pm;
}

@Override
public int getCount() {
    return aListAppInfo.size();
}

@Override
public Object getItem(int position) {
    return aListAppInfo.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}                                                                                       

@Override                                                                                   
public View getView(int position, View convertView, ViewGroup parent) {

    ApplicationInfo entry = aListAppInfo.get(position);

    //positon = position;
    View v = convertView;                                                                   // convertView

                                                                                            // recyklovace
    if(v == null) {
        LayoutInflater inflater = LayoutInflater.from(aContext);
        v = inflater.inflate(R.layout.layout_appinfo, null);
    }
                                                                                            // nahrat layout
    ImageView ivAppIcon = (ImageView)v.findViewById(R.id.ivIcon);
    TextView tvAppName = (TextView)v.findViewById(R.id.tvName);
    TextView tvPkgName = (TextView)v.findViewById(R.id.tvPack);
    chAppStat = (CheckBox)v.findViewById(R.id.chBox);
    //text = entry.packageName;
    chAppStat.setTag(entry.packageName);

    chAppStat.setOnCheckedChangeListener(aListener); 


                                                                                            // privest na vystup

        ivAppIcon.setImageDrawable(entry.loadIcon(aPackManager));
        tvAppName.setText(entry.loadLabel(aPackManager));
        tvPkgName.setText(entry.packageName);



                                                                                            // navrat view
    return v;
}
OnCheckedChangeListener aListener = new CompoundButton.OnCheckedChangeListener () {

     public void onCheckedChanged( CompoundButton buttonView, boolean isChecked) {   
        if(isChecked = true){


            try {
                Runtime.getRuntime().exec("su");
                Runtime.getRuntime().exec("pm disable "+ buttonView.getTag());

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
        else{
                try {
                    Runtime.getRuntime().exec("pm enable "+ buttonView.getTag());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
        }
     }
};




}

recapitulation: problem is package manager function disable/enable in the application. BUT in terminal is correct "pm disable some.name.package"

try {
                Runtime.getRuntime().exec("su");
                Runtime.getRuntime().exec("pm disable "+ buttonView.getTag());

            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
  • You spawn two processes here. The second one (excuting the "pm ...") will not run as root. – Henry Feb 06 '14 at 21:56
  • I need something to spawn both commands in one process? – user3248215 Feb 06 '14 at 22:19
  • Yes, look here for example http://stackoverflow.com/questions/7666349/understanding-su-request – Henry Feb 06 '14 at 22:22
  • Wau, thanks master its works. And some little question if i disable some aplication, how my aplication know what is disable? need something to save state value? Example boolean? – user3248215 Feb 06 '14 at 22:46

0 Answers0