从卸载的Android prevent应用 [英] Prevent app from Uninstall in Android
问题描述
我想要的东西
我想有一个简单的复选框在我的设置菜单,如果选中将使设备管理我的应用程序,将prevent从得到卸载我的应用程序。
I want to have a simple checkbox in my settings menu, which if checked will ENABLE Device Administration for my app and will prevent my app from getting uninstalled.
未选中时将禁用设备管理的复选框。
The checkbox when unchecked will DISABLE Device Administration.
我的应用程序是关于安全性,需要得到保护,免受越来越卸载。我可以得到一个简单的解决方案,为这个?
My app is about security and needs to be protected from getting uninstalled. Can I get a simple solution for this?
PS - 我读过关于这个文件,但似乎无法得到它的工作。
PS - I have read the documentation about this, but can't seem to get it working.
推荐答案
这是不可能的。你不能对自己的决定,使您的应用程序是设备管理员。欢迎您来引导用户到在设置应用适当的位置,让用户选择,使您的应用程序是一个设备管理员,不过,<一个href=\"http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#ACTION_ADD_DEVICE_ADMIN\"相对=nofollow>通过 ACTION_ADD_DEVICE_ADMIN
。
This is not possible. You cannot decide on your own to make your app be a device administrator. You are welcome to lead the user over to the appropriate spot in the Settings app to have the user elect to make your app be a device administrator, though, via ACTION_ADD_DEVICE_ADMIN
.
例如,本次活动将看它是否已经是一个设备管理(通过 isActiveAdmin()
),那么将推出 ACTION_ADD_DEVICE_ADMIN 如果需要,code>活动:
For example, this activity will see if it is already a device admin (via isActiveAdmin()
), then will launch an ACTION_ADD_DEVICE_ADMIN
activity if needed:
/***
Copyright (c) 2012 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
From _The Busy Coder's Guide to Android Development_
http://commonsware.com/Android
*/
package com.commonsware.android.lockme;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class LockMeNowActivity extends Activity {
private DevicePolicyManager mgr=null;
private ComponentName cn=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cn=new ComponentName(this, AdminReceiver.class);
mgr=(DevicePolicyManager)getSystemService(DEVICE_POLICY_SERVICE);
}
public void lockMeNow(View v) {
if (mgr.isAdminActive(cn)) {
mgr.lockNow();
}
else {
Intent intent=
new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, cn);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
getString(R.string.device_admin_explanation));
startActivity(intent);
}
}
}
(从此示例项目)
这两个演员( EXTRA_DEVICE_ADMIN
和 EXTRA_ADD_EXPLANATION
)是可选的,但他们是一个很好的主意。第一个应该是组件名
确定你的 DeviceAdminReceiver
子类;第二个应该是一个字符串(从字符串资源),这可以解释为什么用户应该让你的应用是设备管理。
The two extras (EXTRA_DEVICE_ADMIN
and EXTRA_ADD_EXPLANATION
) are optional, though they are a good idea. The first one should be a ComponentName
identifying your DeviceAdminReceiver
subclass; the second one should be a string (from a string resource) that explains why the user should make your app be a device admin.
我的应用程序是关于安全性,需要保护得到卸载。
My app is about security and needs to be protected from getting uninstalled.
由于任何人都可以进去,并决定不会让你的应用程序是一个设备管理员(再次,通过设置),然后将其卸载,这是没有太大的防守。
Since anybody can go in and decide to not make your app be a device administrator (again, through Settings), then uninstall it, this is not much of a defense.
这篇关于从卸载的Android prevent应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!