2014-09-13 87 views
1

我希望我的应用程序中使用它的工作原理folling代码有密码保护的卸载...(如应用程序锁)保护卸载[程序]

IM上的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" /> 
+0

您是否找到任何解决方案? – 2015-07-09 09:21:42

回答

0

我不积极,所以请纠正我,如果我错了,但是这可能是一个安全功能被移除。恶意应用程序可能能够创建密码并避免应用程序被删除,从而对设备造成进一步的损害。就像我说的,我可能是错的,但这是一个看似合理的猜测。我注意到4+为了安全而做了一些事情,因为第三方应用程序中发生了大量恶意的东西和漏洞。

+0

你可能是正确的应用程序像“APP LOCK”在市场上存在你认为他们在工作吗? – AndDev 2014-09-13 14:06:54

+0

他们可能正在使用root。他们?由于使用root权限,您可以访问诸如Xposed和CydiaSubstrate(适用于Android)的库,从而允许您覆盖系统类。如果他们使用root权限,那么你可以使用这个来做同样的事情:https://github.com/SpazeDog/rootfw和这个:http://www.cydiasubstrate.com/ – Temena 2014-09-13 19:16:11

+0

这可能会有所帮助。让我正在努力......感谢你的支持。 – AndDev 2014-09-14 04:47:54