需要在锁定屏幕中显示我的应用内容

时间:2016-12-03 10:39:05

标签: android android-layout

我需要创建一个与此unlockar相同的Android应用程序,以便在锁定屏幕中显示我的应用内容。

https://play.google.com/store/apps/details?id=app.unlockar.com&hl=en

2 个答案:

答案 0 :(得分:0)

从广播接收器启动了以下警告对话框,它显示了屏幕被帮助的时间。修改以满足您的需求

//required permissions in manifest
<uses-permission   android:name="android.permission.WAKE_LOCK"/>
      <uses-permission   android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
      <uses-permission   android:name="android.permission.DISABLE_KEYGUARD"/>

//code in my broadcast
    @Override
    public void onReceive(final Context context, final Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
            Window window = (Window) context.getSystemService(Context.WINDOW_SERVICE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
            window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
            window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

            PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "tag");
            wl.acquire();
        }
                            AlertDialog alertDialog = new AlertDialog.Builder(context)
                                    .setTitle("On lock dialog message")
                                    .setMessage(""Notice")
                                    .create();

                            alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                                    | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                                    | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                                    | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
                            alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                            alertDialog.show();
}

希望这会有所帮助

答案 1 :(得分:0)

你应该使用这个标志: FLAG_SHOW_WHEN_LOCKED 例如:

from tkinter import *

Window = Tk() # window

Window.geometry("400x200+50+50") # heightxwidth+x+y
Window.title("Stack Emulator")

mainPanel = Canvas(Window, width = 400, height = 200) # :)
mainPanel.pack() # :)

global stack
stack = Listbox(height = 8)

# methods
def Add(data):
    data = data.get()
    stack.insert(0, data)
    stack.see(0)

def Remove():
    stack.delete(0)
    stack.see(0)

# buttons   
data = StringVar()
enter = Entry(width = 10, textvariable = data)
add = Button(text = "Push", command = lambda *args: Add(data))
remove = Button(text = "Pop", command = lambda *args: Remove())

# stack
mainPanel.create_text(100, 20, text = "Stack", font = ("Purisa", 14, "bold"))
mainPanel.create_window(100, 35, window = stack, anchor = "n")
mainPanel.create_rectangle(37, 34, 162, 167)

# methods
mainPanel.create_text(180, 40, text = "Element:", font = ("Purisa", 12), anchor = "nw")
mainPanel.create_window(250, 40, window = enter, anchor = "nw")
mainPanel.create_window(180, 60, window = add, anchor = "nw")
mainPanel.create_window(180, 90, window = remove, anchor = "nw")