简体   繁体   中英

password protected uninstall in android 4+ versions [programmatically]

i want my app to have a password protected uninstall ... (like app lock)

im using folling code it works on Android 2.3 but not on Android 4+ versions

MANIFEST FILE

  <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>

Uninstalling Activity code

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" />

I am not positive, so please correct me if I'm wrong but this might have been removed as a security feature. A malicious app might be able to create a password and avoid the app from being removed creating further damage on the device. Like I said, I could be wrong but this is a guess that seems legit. I noticed that 4+ did a couple things for security because of a lot of malicious stuff and exploits happening within 3rd party apps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM