我在通过包管理器功能禁用/启用禁用应用程序时遇到问题。 在android终端中都是corect,但在这个应用程序中没有。但是“Runtime.getRuntime()。exec(”su“);”正常运行并执行他的活动。
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:问题是应用程序中的包管理器功能禁用/启用。但在终端中是正确的“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();
}
}