Question

I have developed a custom lockscreen but I will want to make the notification/status bar to don't scroll if my app have a security password.

I found that if I add

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}

I can't scroll the status bar, but I have to set a secure system lock. So my question is, could I implement the same things, but without the need of activating a system secure lock?

Was it helpful?

Solution

  1. That's not possible to achieve without enabling one or another type (face unlock, pattern, pin, password) of screen lock.

  2. Possible on rooted devices through reflection (regardless whether screen lock is enabled or not). Your app will need to have "android.permission.STATUS_BAR" permission which is protection level is "signature|system". That's either your app needs to be signed with the platform key or has to be a system application.

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.disablestatusbar"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.STATUS_BAR" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.disablestatusbar.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MainActivity.java:

package com.example.disablestatusbar;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import android.os.Bundle;
import android.app.Activity;

public class MainActivity extends Activity {

    private Object mStatusBarManager;
    private static final String STATUS_BAR_SERVICE = "statusbar";
    private static final int DISABLE_NONE = 0x00000000;
    private static final int STATUS_BAR_DISABLE_EXPAND = 0x00010000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mStatusBarManager = getSystemService(STATUS_BAR_SERVICE);
    }

    @Override
    protected void onResume() {
        super.onResume();
        disableStatusbarExpand(STATUS_BAR_DISABLE_EXPAND);
    }

    @Override
    protected void onPause() {
        super.onPause();
        disableStatusbarExpand(DISABLE_NONE);
    }

    private void disableStatusbarExpand(int what) {
        try {
            Method disable = mStatusBarManager.getClass().getMethod("disable", int.class);
            try {
                disable.invoke(mStatusBarManager, what);
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } catch (NoSuchMethodException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top