public class MyMainActivity extends ListActivity {
int x;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
loadApps();
}
private void loadApps() {
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> mApps = getPackageManager().queryIntentActivities(
mainIntent, 0);
ListView listView = getListView();
listView.setAdapter(new AppsAdapter(this, mApps));
}
public class AppsAdapter extends BaseAdapter {
private LayoutInflater inflater;
private List<ResolveInfo> mApps;
public AppsAdapter(Context context, List<ResolveInfo> mApps) {
this.inflater = LayoutInflater.from(context);
this.mApps = mApps;
}
class ViewHandler {
TextView textLable;
ImageView iconImage;
Button buttn;
}
public View getView(final int position, View convertView,
ViewGroup parent) {
final ViewHandler Handler;
if (convertView == null) {
convertView = inflater.inflate(R.layout.customlist, null);
Handler = new ViewHandler();
Handler.textLable = (TextView) convertView
.findViewById(R.id.TV);
Handler.iconImage = (ImageView) convertView
.findViewById(R.id.IV);
Handler.buttn = (Button) convertView.findViewById(R.id.buttonx);
convertView.setTag(Handler);
} else {
Handler = (ViewHandler) convertView.getTag();
}
ResolveInfo info = this.mApps.get(position);
Handler.iconImage.setImageDrawable(info
.loadIcon(getPackageManager()));
Handler.textLable.setText(info.loadLabel(getPackageManager()));
Handler.buttn.setOnClickListener(new OnClickListener() {
boolean isClicked = false;
@Override
public void onClick(View v) {
if (isClicked == false) {
Handler.buttn.setBackgroundResource(R.drawable.locker);
Toast.makeText(getApplicationContext(), "" + position,
Toast.LENGTH_SHORT).show();
isClicked = true;
} else {
Handler.buttn
.setBackgroundResource(R.drawable.unlocked);
isClicked = false;
}
}
});
return convertView;
}
public final int getCount() {
return mApps.size();
}
public final Object getItem(int position) {
return mApps.get(position);
}
public final long getItemId(int position) {
return position;
}
}
}
请告诉我如何从菜单中隐藏所有应用程序中的应用程序,我只是想创建一个应用程序隐藏应用程序,出于安全性或个人原因,如果有人想要隐藏他或她将使用我的应用程序的应用程序,这就是为什么我想知道如何隐藏应用程序
答案 0 :(得分:0)
您可以使用以下内容隐藏该应用:
PackageManager pm = getApplicationContext().getPackageManager();
pm.setComponentEnabledSetting(<component of the main Activity of the app you want to hide>, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
请记住,这也会禁用该应用,因此它不会响应更多意图等。如果您希望应用保持启用状态,则必须编写自己的主屏幕并允许用户隐藏图标。当用户隐藏图标时,您可以让启动器停止在列表中显示它。
答案 1 :(得分:0)
非常简单。
如果您有Packagename(很容易获得!),您可以使用以下代码启用disable。请注意您将需要权限,然后您不能更改其他应用程序(因为用户ID)。
public void disableDrawerIcon(String component) {
try {
PackageManager pm = _context.getApplicationContext()
.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> appList = pm.queryIntentActivities(mainIntent, 0);
Collections
.sort(appList, new ResolveInfo.DisplayNameComparator(pm));
ComponentName componentName = null;
for (ResolveInfo temp : appList) {
if (temp.activityInfo.packageName.equals(component)) {
componentName = new ComponentName(component,
temp.activityInfo.name);
}
}
if (componentName != null) {
pm.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
CustomLogger.log(TAG, "Icon disabled", _context);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void enableDrawerIcon(String component) {
try {
PackageManager pm = _context.getApplicationContext()
.getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> appList = pm.queryIntentActivities(mainIntent, 0);
Collections
.sort(appList, new ResolveInfo.DisplayNameComparator(pm));
ComponentName componentName = null;
for (ResolveInfo temp : appList) {
if (temp.activityInfo.packageName.equals(component)) {
componentName = new ComponentName(component,
temp.activityInfo.name);
}
}
if (componentName != null) {
}
pm.setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
CustomLogger.log(TAG, "Icon enabled", _context);
} catch (Exception e) {
e.printStackTrace();
}
}