如何在Android中使应用程序锁定应用程序? [英] How to make app lock app in android?
问题描述
我必须为Android开发一个应用程序储物柜,以便用户可以阻止应用程序,而其他用户如果没有访问键就无法访问这些应用程序.
I have to develop an app locker for Android where the user can block apps and other users can not access these apps without an access key.
我已经安装了一个应用程序,但是我不知道如何锁定该应用程序.
I have installed an app but I don't know how to lock this app.
请给我一些建议.
推荐答案
这不是堆栈溢出的工作方式.您甚至都无法尝试就无法提出完整的解决方案.
This is not how stack overflow works. You can not ask a complete solution without even trying anything.
对于最基本的应用程序版本,您需要执行三个功能.
For the most basic version of your app, you need to perform three functions.
-
获取设备上所有已安装应用程序的列表,并在带有复选框的ListView中显示它们.如果用户检查了任何应用程序,则将该应用程序添加到另一个列表中,例如BlockedAppsList(这将是用户要阻止的应用程序列表). 您可以使用以下代码安装所有应用程序:
Get a list of all the installed apps on device and show them in a ListView with check box. If the user checks any app, add the app to a different list say BlockedAppsList(which will be the list of apps which user wants to block). You can get all the apps installed using the following code:
final PackageManager pm = getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
Log.d(TAG, "Installed package :" + packageInfo.packageName);
Log.d(TAG, "Source dir : " + packageInfo.sourceDir);
Log.d(TAG, "Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName));
}
检查哪个是当前打开的应用程序.您可以使用以下代码进行检查:
Check the which is the current opened app. You can check by using this code:
ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List l = am.getRecentTasks(1, ActivityManager.RECENT_WITH_EXCLUDED);
Iterator i = l.iterator();
PackageManager pm = this.getPackageManager();
while (i.hasNext()) {
ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next());
try {
CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(
info.processName, PackageManager.GET_META_DATA));
Log.w("LABEL", c.toString());
} catch (Exception e) {
// Name Not FOund Exception
}
}
现在检查BlockedAppsList中是否存在当前应用程序,如果存在,则可以显示带有阻止消息的任何屏幕.
Now check if the current app is present in the BlockedAppsList, if it is there, you can show any screen with a block message.
祝你好运!
这篇关于如何在Android中使应用程序锁定应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!