如何在android中制作应用程序锁定应用程序? [英] How to make app lock app in android?

查看:43
本文介绍了如何在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.

  1. 获取设备上所有已安装应用程序的列表,并在带有复选框的 ListView 中显示它们.如果用户检查任何应用程序,将应用程序添加到不同的列表,比如 BlockedAppsList(这将是用户想要阻止的应用程序列表).您可以使用以下代码安装所有应用:

  1. 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屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆