android 4+版本中的密码保护卸载[编程]

时间:2014-09-13 04:22:34

标签: android broadcastreceiver uninstall password-protection

我希望我的应用程序拥有受密码保护的卸载程序...(例如应用程序锁定)

我正在使用folling代码,它适用于 Android 2.3 但不适用于 Android 4 + 版本

预告文件

  <receiver android:name="fyp.invisibleink.UninstallIntentReceiver" >
        <intent-filter android:priority="0" >
            <action android:name="android.intent.action.QUERY_PACKAGE_RESTART" />

            <data android:scheme="package" />
        </intent-filter>
    </receiver>

卸载活动代码

ublic class Uninstalling extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_uninstalling);

    // listener
    Button settingsBtn = (Button) findViewById(R.id.btnu);
    settingsBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            final EditText e1 = (EditText) findViewById(R.id.etpass);

            final String pass = e1.getText().toString();

            SharedPreferences cupSetting = getSharedPreferences(
                    "cuppassword", Context.MODE_PRIVATE);
            String mypass = cupSetting.getString("pass", "");

            if (pass.equals(mypass)) {
                Toast.makeText(getApplicationContext(),
                        "password is correct!", Toast.LENGTH_LONG).show();
                Toast.makeText(getApplicationContext(),
                        "press OK to uninstall!", Toast.LENGTH_LONG).show();
                finish();

            } else {
                Toast.makeText(getApplicationContext(),
                        "Access Denied! try again", Toast.LENGTH_LONG)
                        .show();
                e1.setText("");

            }
        }
    });

}

UninstallReceveier

public class UninstallIntentReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    // fetching package names from extras
    String[] packageNames = intent
            .getStringArrayExtra("android.intent.extra.PACKAGES");

    if (packageNames != null) {
        for (String packageName : packageNames) {
            if (packageName != null
                    && packageName.equals("com.example.invisibleink")) {
                // User has selected our application under the Manage Apps
                // settings
                // now initiating background thread to watch for activity
                new ListenActivities(context).start();

            }
        }
    }
}

// ///////////////////////////////
class ListenActivities extends Thread {
    boolean exit = false;
    ActivityManager am = null;
    Context context = null;

    public ListenActivities(Context con) {
        context = con;
        am = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
    }

    @Override
    public void run() {

        Looper.prepare();

        while (!exit) {

            // get the info from the currently running task
            List<ActivityManager.RunningTaskInfo> taskInfo = am
                    .getRunningTasks(MAX_PRIORITY);

            String activityName = taskInfo.get(0).topActivity
                    .getClassName();

            Log.d("topActivity", "CURRENT Activity ::" + activityName);

            if (activityName
                    .equals("com.android.packageinstaller.UninstallerActivity")) {
                // User has clicked on the Uninstall button under the Manage
                // Apps settings

                Intent intent = new Intent(context, Uninstalling.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
                exit = true;
                // do whatever pre-uninstallation task you want to perform
                // here
                // show dialogue or start another activity or database
                // operations etc..etc..

                // context.startActivity(new Intent(context,
                // MyPreUninstallationMsgActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

            } else if (activityName
                    .equals("com.android.settings.ManageApplications")) {
                // back button was pressed and the user has been taken back
                // to Manage Applications window
                // we should close the activity monitoring now
                exit = true;
            }
        }
        Looper.loop();
    }
}

}


Permissioms

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

1 个答案:

答案 0 :(得分:0)

我不是正面的,所以如果我错了请纠正我,但这可能已被删除作为安全功能。恶意应用程序可能能够创建密码并避免删除应用程序,从而对设备造成进一步的破坏。就像我说的,我可能是错的,但这是一个似乎合法的猜测。我注意到4+为了安全起见做了一些事情,因为第三方应用程序中发生了很多恶意内容和漏洞利用。