如何以编程方式为应用设置锁或固定编辑:(获取棒棒糖的顶级包装名称)
2022-09-02 21:44:50
所以现在我正试图为我年幼的孩子开发一个Android应用程序。我想在选定的应用程序上设置一个或多个密码,以阻止它们打开应用程序。例如,假设我的女儿想在我工作时在手机上玩愤怒的小鸟一段时间。我会选择我的重要应用程序,如消息传递,gmail等,并在她玩愤怒的小鸟时将PIN或密码放在上面30分钟。30分钟后,我从女儿那里拿到手机,我可以在没有别针的情况下打开应用程序,因为时间限制已过期。
我对此做了大量的研究,但我无法为我的特定情况找到实现。
我知道应用程序锁具有与我想要做的类似的结构。我只是为锁设置一个时间限制。
https://play.google.com/store/apps/details?id=com.domobile.applock&hl=en
我正在远离使用活动管理器等杀死活动/应用程序。我真的只是想要在特定时间内在选定的应用程序上获得干净的锁定屏幕。
我有一个倒计时计时器,用于在我设置的时间倒计时。如果我拥有所有包名,如何修改此代码以在选定的时间内阻止某些应用程序?
start_timer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new AlertDialog.Builder( MainActivity.this )
.setMessage( "Are you sure you want to block the selected apps for the set amount of time?" )
.setPositiveButton( "Yeah man!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.d( "AlertDialog", "Positive" );
hourint = Integer.valueOf(number_text.getText().toString());
minuteint = Integer.valueOf(minute_text.getText().toString());
secondint = Integer.valueOf(second_text.getText().toString());
Log.i("YourActivity", "Hours: " + hourint);
Log.i("YourActivity", "Minutes: " + minuteint);
Log.i("YourActivity", "Seconds: " + secondint);
totalTimeCountInMilliseconds = ((hourint*60*60) +(minuteint*60) + (secondint)) * 1000; // time count
timeBlinkInMilliseconds = 30*1000;
countDownTimer = new CountDownTimer(totalTimeCountInMilliseconds, 500) {
// 500 means, onTick function will be called at every 500 milliseconds
@Override
public void onTick(long leftTimeInMilliseconds) {
Context context = MainActivity.this;
long seconds = leftTimeInMilliseconds / 1000;
mSeekArc.setVisibility(View.INVISIBLE);
start_timer.setVisibility(View.INVISIBLE);
block_button1.setVisibility(View.INVISIBLE);
if ( leftTimeInMilliseconds < timeBlinkInMilliseconds ) {
// textViewShowTime.setTextAppearance(getApplicationContext(), R.style.blinkText);
// change the style of the textview .. giving a red alert style
if ( blink ) {
number_text.setVisibility(View.VISIBLE);
minute_text.setVisibility(View.VISIBLE);
second_text.setVisibility(View.VISIBLE);
// if blink is true, textview will be visible
} else {
number_text.setVisibility(View.INVISIBLE);
minute_text.setVisibility(View.INVISIBLE);
second_text.setVisibility(View.INVISIBLE);
}
blink = !blink; // toggle the value of blink
}
second_text.setText(String.format("%02d", seconds % 60));
minute_text.setText(String.format("%02d", (seconds / 60) % 60));
number_text.setText(String.format("%02d", seconds / 3600)); // format the textview to show the easily readable format
}
@Override
public void onFinish() {
// this function will be called when the timecount is finished
//textViewShowTime.setText("Time up!");
number_text.setVisibility(View.VISIBLE);
minute_text.setVisibility(View.VISIBLE);
second_text.setVisibility(View.VISIBLE);
mSeekArc.setVisibility(View.VISIBLE);
start_timer.setVisibility(View.VISIBLE);
block_button1.setVisibility(View.VISIBLE);
}
}.start();
}
})
.setNegativeButton("Nope!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.d("AlertDialog", "Negative");
dialog.cancel();
}
})
.show();