我想通过选中复选框来卸载多个应用程序..问题是,当我检查多个应用程序以卸载时,每次都警告“您确定要卸载此应用程序吗”。我只想要一个警报,代码会卸载所有已检查的应用程序。
private void displayListView() {
ArrayList<App> appList = new ArrayList<App>();
App app = null;
List<PackageInfo> list = getPackageManager().getInstalledPackages(0);
String name = "";
String path = "";
String capName = "";
for (PackageInfo p : list) {
if ((p.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
} else {
name = p.applicationInfo.loadLabel(getPackageManager())
.toString();
capName = getApplicationContext().getPackageName();
path = p.applicationInfo.packageName;
if ((!name.equals("com.android.gesture.builder"))
&& (!capName.equals(path))) {
app = new App(path, name, false);
app.setVersionCode(p.versionCode);
app.setVersionName(p.versionName);
app.setIcon(p.applicationInfo.loadIcon(getPackageManager()));
appList.add(app);
}
}
}
// create an ArrayAdaptar from the String Array
dataAdapter = new MyCustomAdapter(this, R.layout.layout_app_list,
appList);
ListView listView = (ListView) findViewById(R.id.listView1);
// Assign adapter to ListView
listView.setAdapter(dataAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// app app = (app)
// parent.getItemAtPosition(position);
App ap = (App) parent.getItemAtPosition(position);
// Toast.makeText(getApplicationContext(), ap.getName(),
// Toast.LENGTH_SHORT).show();
Intent itn = new Intent(AppManagement.this, AppInfo.class);
Bundle extras = new Bundle();
extras.putString("name", ap.getName());
extras.putString("path", ap.getpath());
extras.putString("vName", ap.getVersionName());
extras.putString("vCode", ap.getVersionCode() + "");
itn.putExtras(extras);
startActivity(itn);
}
});
}
public void checkButtonClick() {
Button myButton = (Button) findViewById(R.id.findSelected);
myButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
StringBuffer responseText = new StringBuffer();
ArrayList<App> appList = dataAdapter.appList;
App app = null;
for (int i = 0; i < appList.size(); i++) {
app = appList.get(i);
if (app.isSelected()) {
urr = Uri.fromParts("package", app.getpath(), null);
Log.d("", urr.toString());
responseText.append("\n" + app.getName() + " \t "
+ app.getpath());
Intent intent = new Intent(Intent.ACTION_DELETE, urr);
startActivityForResult(intent, 1);
}
}
if (responseText.length() == 0) {
Toast.makeText(getApplicationContext(), "No App selected ",
Toast.LENGTH_SHORT).show();
} else {
// Toast.makeText(getApplicationContext(), responseText,
// Toast.LENGTH_LONG).show();
}
}
});
}
public void onActivityResult(int rCode, int resultCode, Intent data) {
if (rCode == 1) {
if (resultCode == RESULT_OK) {
Toast.makeText(this, "Ok", Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED) {
displayListView();
}
}
}
答案 0 :(得分:0)
目前第三方应用程序无法使用此功能。每次安装/卸载时,您都必须获得用户的许可。