2014-09-13 93 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