启动器应用程序用于阻止通知栏和主页按钮长按设置

时间:2016-01-06 01:30:17

标签: android android-launcher

我公司的前任开发人员创建了一个应用程序,用作多种Android手机的启动器。这些电话被发放给员工用于商业目的,因此应用程序限制了手机对我们允许的应用程序的访问。

该应用程序适用于所有版本的Android,直到Lollipop。在具有棒棒糖的手机上,用户可以从通知栏访问设置(应用程序在以前版本的Android上阻止的内容),并且通过长按主页按钮,谷歌应用程序也会启动(也是在版本低于lollipop的手机上被应用程序阻止。此应用程序的软件包名称为com.google.android.googlequicksearchbox)。

我一直在研究这个问题几天,我无法弄清楚棒棒糖的变化是什么让应用停止工作。我在一个运行棒棒糖的motorolla turbo 2和galaxy s5上试过它,两者都存在问题。


我尝试了多种解决方案:

Override or disable settings menu 此链接不起作用,因为它基本上会在每次用户尝试访问设置时运行我的应用程序,这是我们仍然作为某些人的管理权限提供的功能

Detect home button press in android 我尝试了这个链接,以及其他链接来覆盖主页按钮上长按的功能,但我无法在主页按钮上捕获按下。


问题:

Q1: 有没有办法禁止从通知栏访问设置,比如隐藏通知栏中的设置图标,甚至完全禁用通知栏?

Q2: 有没有办法拦截主页按钮上的长按或更改主页按钮长按的功能? 任何帮助将非常感激。谢谢

2 个答案:

答案 0 :(得分:0)

问题已修复。
应用程序逻辑是使用前台应用程序包 在棒棒糖更新后无效的getRunningTasks(int maxNum),所以我在这个问题的答案中添加了代码:How to get recent tasks on Android "L"?

谢谢Marcin Orlowski

答案 1 :(得分:0)

要阻止用户访问系统设置,您可以像这样

覆盖活动的onPause()方法。
 @Override
    protected void onPause() {
        super.onPause();

        ActivityManager activityManager = (ActivityManager) getApplicationContext()
                .getSystemService(Context.ACTIVITY_SERVICE);

        activityManager.moveTaskToFront(getTaskId(), 0);
    }

这将在您的活动运行时阻止访问 最好的解决方案是创建一个extends AccessibilityService的服务,然后像这样

覆盖onAccessibilityEvent方法
  @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {
        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {


                AppChecker appChecker = new AppChecker();
                Toast.makeText(getApplicationContext(), "new app started", Toast.LENGTH_LONG).show();
                String packageName = appChecker.getForegroundApp(getApplicationContext());
                if ( packageName.equals("com.android.settings")){
                    KillApplication(packageName);
                }

        }
    }

AppChecker是可在github上获得的android库,请查看此链接https://github.com/ricvalerio/foregroundappchecker

KillApplication就是这样的方法

public void KillApplication(String KillPackage)
{
    ActivityManager am = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(startMain);



am.killBackgroundProcesses(KillPackage);
Toast.makeText(getBaseContext(),"Process Killed : " + KillPackage  ,Toast.LENGTH_LONG).show();
}

AndroidManifest.xml 将其合并到您的清单中:

<service
            android:name=".YourForeGroundService"
            android:enabled="true"
            android:exported="true"
            android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
            >

            <intent-filter>
                <action android:name="android.accessibilityservice.AccessibilityService"/>
            </intent-filter>
            <meta-data
                android:name="android.accessibilityservice"
                android:resource="@xml/accessibilityservice"/>

        </service>

服务信息 将其放入res/xml/accessibilityservice.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- These options MUST be specified here in order for the events to be received on first
 start in Android 4.1.1 -->
<accessibility-service
    xmlns:tools="http://schemas.android.com/tools"
    android:accessibilityEventTypes="typeWindowStateChanged"
    android:accessibilityFeedbackType="feedbackGeneric"
    android:accessibilityFlags="flagIncludeNotImportantViews"

    xmlns:android="http://schemas.android.com/apk/res/android"
    tools:ignore="UnusedAttribute"/>

启用服务 应用程序的每个用户都需要显式启用AccessibilityService才能使用它。 //主屏幕>系统设置>辅助功能>辅助功能服务>我的应用程序>从关闭更改为开启,

AndroidManifest 文件

中允许这些权限
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />

祝你愉快