gpt4 book ai didi

android - 如何以编程方式锁定 Activity 操作

转载 作者:行者123 更新时间:2023-11-29 14:14:45 25 4
gpt4 key购买 nike

想要锁定 Activity 操作,如果用户在 AlertDialog 中点击 Yes,但当我点击 Yes 时似乎没有任何反应。

我正在关注 this解决方案

AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.this);

// Setting Dialog Title
alertDialog.setTitle("Confirm Delete...");

// Setting Dialog Message
alertDialog.setMessage("Are you sure you want delete this?");

// Setting Icon to Dialog
alertDialog.setIcon(R.drawable.delete);

// Setting Positive "Yes" Button
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {

PackageManager pm = getPackageManager();
pm.setComponentEnabledSetting(new ComponentName(getApplicationContext(), com.example.lock.MainActivity.class),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
});

// Setting Negative "NO" Button
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke NO event
dialog.cancel();
}
});

// Showing Alert Message
alertDialog.show();

最佳答案

使用这个。它有效:)

` try using this flags to disable lock screen when the activity is started.

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

关于android - 如何以编程方式锁定 Activity 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24818067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com