我们可以创建一个BroadcastReceiver来检测何时启动(打开)任何已安装的应用程序

时间:2014-03-05 09:07:52

标签: android

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;

public class KeypadActivity extends Activity {
    static int flag = 1;
    Button btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9,
            btnclear, btnenter;
    TextView tv;
     String password;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.keypad);
        addListenerOnButton();
    }

    public void addListenerOnButton() {
        // TODO Auto-generated method stub
        btn0 = (Button) findViewById(R.id.btn0);
        btn1 = (Button) findViewById(R.id.btn1);
        btn2 = (Button) findViewById(R.id.btn2);
        btn3 = (Button) findViewById(R.id.btn3);
        btn4 = (Button) findViewById(R.id.btn4);
        btn5 = (Button) findViewById(R.id.btn5);
        btn6 = (Button) findViewById(R.id.btn6);
        btn7 = (Button) findViewById(R.id.btn7);
        btn8 = (Button) findViewById(R.id.btn8);
        btn9 = (Button) findViewById(R.id.btn9);
        btnclear = (Button) findViewById(R.id.btnx);
        btnenter = (Button) findViewById(R.id.btnenter);

        tv = (TextView) findViewById(R.id.textView1);

        btn0.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tv.append(btn0.getText().toString());
            }
        });

        btn1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tv.append(btn1.getText().toString());
            }
        });
        btn2.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tv.append(btn2.getText().toString());
            }
        });
        btn3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tv.append(btn3.getText().toString());
            }
        });
        btn4.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tv.append(btn4.getText().toString());
            }
        });
        btn5.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tv.append(btn5.getText().toString());
            }
        });
        btn6.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tv.append(btn6.getText().toString());
            }
        });
        btn7.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tv.append(btn7.getText().toString());
            }
        });
        btn8.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tv.append(btn8.getText().toString());
            }
        });
        btn9.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                tv.append(btn9.getText().toString());
            }
        });
        btnclear.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                String str = tv.getText().toString().trim();
                if (str.length() != 0) {
                    str = str.substring(0, str.length() - 1);

                    tv.setText(str);
                }
            }
        });


        btnenter.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub



                password=tv.getText().toString();
                Intent intent = new Intent(KeypadActivity.this, KeypadActivity2.class);
                intent.putExtra("password",password);
                startActivity(intent);

        }
    });
}}

我在Android中制作App-locker,我在系统中安装了应用程序列表。单击复选框我在某些应用程序上设置了密码。现在我想要用我的应用程序锁定多少个应用程序,如果用户打开锁定应用程序然后在打开该应用程序之前必须打开我的密码验证活动(KeypadActivity.java)。

0 个答案:

没有答案