我试图检测BroadcastReceiver类中何时按下电源按钮,实际上我在激活设备管理员权限时实现它.我有谷歌这么多,但无法找到它.
在广播接收器类中,当屏幕为ON和OFF时,我正在使用此方法检测它
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF))
{
Log.v("Screen Off", "Screen OFF");
}
else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON))
{
Log.v("Screen ON", "Screen ON");
}
Run Code Online (Sandbox Code Playgroud)
但我必须检测何时仅按下电源按钮.有一点,我想说清楚有很多应用程序正在执行此功能,例如:https://play.google.com/store/apps/details? id = com.startv.gumrah.这是很多使用对于SOS应用程序
紧急应用程序,连续2次点击智能手机的电源按钮开始发送警报消息
请帮助我按下电源按钮时如何检测.
我想实现一个KioskMode,我只针对Android L,因为这是一个非常具体的应用程序。
我已经完成了将我的应用程序设置为 DeviceAdmin 的过程,并且
DevicePolicyManager.isLockTaskPermitted(this.getPackageName())已经返回true.
然后我开始一个LockTaskvia startLockTask()。
一切都很好,但是当我按住 时backbutton,应用程序仍会退出自助服务终端模式。
我已覆盖onKeyPress以显示用于解锁应用程序的自定义对话框,但这并不妨碍 android 在用户按下时自动退出我的锁定任务。
我现在真的不知道该怎么做,我会很感激每一个输入。
我现在已经覆盖
@Override
public boolean onKeyDown(int KeyCode, KeyEvent event)
{
if(KeyCode == KeyEvent.KEYCODE_BACK)
{
BackDownButtonPressed = true;
if(VolDownPressed)
showTaskLockDialog();
return true;
}
else if(KeyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
{
VolDownPressed = true;
if(BackDownButtonPressed)
showTaskLockDialog();
return true;
}
return super.onKeyDown(KeyCode, event);
}
@Override
public boolean onKeyUp(int KeyCode, KeyEvent event) {
if(KeyCode == KeyEvent.KEYCODE_BACK)
{
BackDownButtonPressed = …Run Code Online (Sandbox Code Playgroud) 我是设备管理员应用程序,我想通过手动安装更新.问题是当应用程序处于管理员模式时我没有得到安装弹出由android生成安装apk但当取消固定或删除应用程序作为设备管理员我是获得安装对话框.我接近了两种方法
第一种方法:使用intent安装apk
Intent intentInstall = new Intent(Intent.ACTION_VIEW);
intentInstall.setDataAndType(Uri.fromFile(new File(Constants.UPDATE_APK_PATH)), "application/vnd.android.package-archive");
intentInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // without this flag android returned a intent error!
AppApplication.getContext().startActivity(intentInstall);
Run Code Online (Sandbox Code Playgroud)
仅当app未设置为设备管理员时,此方法才有效
第二种方法:使用PackageManger进行无提示安装
PackageManager packageManger = mContext.getPackageManager();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
PackageInstaller packageInstaller = packageManger.getPackageInstaller();
String packageName = mContext.getPackageName();
PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(
PackageInstaller.SessionParams.MODE_FULL_INSTALL);
params.setAppPackageName(packageName);
try {
int sessionId = packageInstaller.createSession(params);
PackageInstaller.Session session = packageInstaller.openSession(sessionId);
OutputStream out = session.openWrite(packageName + ".apk", 0, -1);
readTo(Constants.UPDATE_APK_PATH, out); //read the apk content and write it to out …Run Code Online (Sandbox Code Playgroud) 我能够遵循并完成设备管理示例。我可以成功锁定、擦除数据并执行其他管理任务。
案例1:我注意到的问题是,每当我禁用设备管理员(设置->安全->选择设备管理员)然后重新启动设备时,重新启动后设备管理员会再次启用。
案例 2:即使在我安装了我的应用程序并且没有通过我的应用程序激活设备管理员之后。重启后设备管理员仍处于启用状态。
这是重启后的设备管理员功能吗?还是限制?可能有什么问题?需要一些帮助。谢谢
E/AndroidRuntime(27856): java.lang.RuntimeException: Unable to instantiate receiver com.inc.statusbar.Statusbar$DeviceAdminSampleReceiver: java.lang.InstantiationException: can't instantiate class com.inc.statusbar.Statusbar$DeviceAdminSampleReceiver; no empty constructor
Run Code Online (Sandbox Code Playgroud)
我已经尝试调用DeviceAdminReceiver类的默认构造函数但无济于事。删除构造函数也给出了同样的错误。
DeviceAdminSampleReceiver类定义 -
public class DeviceAdminSampleReceiver extends DeviceAdminReceiver
{
public DeviceAdminSampleReceiver()
{
super();
}
@Override
public void onEnabled(Context context, Intent intent) {
super.onEnabled(context, intent);
}
@Override
public CharSequence onDisableRequested(Context context, Intent intent) {
super.onDisabled(context, intent);
return "admin_receiver_status_disable_warning";
}
@Override
public void onDisabled(Context context, Intent intent) {
super.onDisabled(context, intent);
}
}
Run Code Online (Sandbox Code Playgroud) 似乎有些DeviceAdmin功能已在Lollipop中被破坏,至少在我的Nexus 5上是这样.
这适用于KitKat,JellyBean和Ice Cream Sandwich
@Override
public void onPasswordFailed(Context context, Intent intent) {
DevicePolicyManager policyManager = (DevicePolicyManager)context.getSystemService(Context.DEVICE_POLICY_SERVICE);
if(policyManager != null){
int attempts = policyManager.getCurrentFailedPasswordAttempts();
Log.v("TAG", "Attempts = " + attempts);
}
}
Run Code Online (Sandbox Code Playgroud)
但在使用Android 5.0 Lollipop的Nexus 5上,它会产生以下错误:
11-24 16:11:50.117 27053-27053/com.example.myapp E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.example.myapp, PID: 27053
java.lang.RuntimeException: Unable to start receiver com.example.myapp.receivers.AdminReceiver: java.lang.NullPointerException: Attempt to read from field 'int android.content.pm.UserInfo.id' on a null object reference
at android.app.ActivityThread.handleReceiver(ActivityThread.java:2586)
at android.app.ActivityThread.access$1700(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native …Run Code Online (Sandbox Code Playgroud) 我想知道设备管理员和配置文件所有者是如何工作的。我遵循了谷歌网站上的一些例子,但我仍然不太清楚个人资料所有者是如何工作的。
为了测试这一点,我构建了一个示例应用程序,它将要求用户接受配置文件所有者,然后在无需用户交互的情况下安装证书。
应个人资料所有者的要求,我在我的活动中执行了以下操作:
Intent intent = new Intent(ACTION_PROVISION_MANAGED_PROFILE);
intent.putExtra(EXTRA_PROVISIONING_DEVICE_ADMIN_PACKAGE_NAME, getApplicationContext().getPackageName());
startActivityForResult(intent, REQUEST_PROVISION_MANAGED_PROFILE);
Run Code Online (Sandbox Code Playgroud)
在我的接收器上我有这样的东西:
@Override
public void onProfileProvisioningComplete(Context context, Intent intent) {
// Enable the profile
DevicePolicyManager manager =
(DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
ComponentName componentName = getComponentName(context);
manager.setProfileName(componentName, context.getString(R.string.profile_name));
// If I do not do this, the application will not enter in profile mode, and I don't know why
Intent launch = new Intent(context, MainActivity.class);
launch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(launch);
}
Run Code Online (Sandbox Code Playgroud)
在这里,我不知道为什么需要重新启动应用程序,以便我可以进入配置文件所有者模式。不过,当我让配置文件所有者工作并关闭应用程序并再次启动它时,我不会恢复配置文件所有者模式。
我正在通过在应用程序 OnCreate() 方法上执行类似的操作来检查配置文件所有者模式是否处于活动状态:
if (!mDeviceController.isProfileActive()) {
Log.i("DeviceAdminSample", "Profile is disabled!!!!!");
}
Run Code Online (Sandbox Code Playgroud)
为什么当我重新启动应用程序时,配置文件所有者被禁用?有什么方法可以避免用户每次打开应用程序时都启用配置文件所有者模式?
此外,如果我使用此机制安装证书,其他应用程序仍然可以使用此证书,或者该证书仅适用于创建的配置文件?
有一些应用程序可以检测何时从电话/设备管理员中删除它们。我在 Android 开发人员网站上搜索过,但找不到当用户单击电话/设备管理器中应用程序旁边的“勾号”复选框时触发的标志或接收器。
所以我试图让一个一次性使用的专用应用程序 + 设备在自助服务终端模式 + 自动启动下工作。应用程序本身是用 Nativescript(使用 Angular)构建的,所以不是原生 Java,但是这仍然是通过管理接收器等正常处理的。
当我们adb用来设置设备所有者时,kiosk 模式按预期工作。
adb shell dpm set-device-owner com.domain.app/.DeviceAdminReceiver
Run Code Online (Sandbox Code Playgroud)
当我们使用 Android 管理策略注册设备并自动安装时,自助服务终端模式永远不会正确启动。
{
"name": "enterprises/LC00mpaqaj/policies/policy1",
"version": "12",
"applications": [
{
"packageName": "com.domain.app",
"installType": "FORCE_INSTALLED",
"lockTaskAllowed": true,
"defaultPermissionPolicy": "GRANT"
}
],
"persistentPreferredActivities": [
{
"receiverActivity": "com.domain.app/.DeviceAdminReceiver",
"actions": [
"android.intent.action.MAIN"
],
"categories": [
"android.intent.category.HOME",
"android.intent.category.DEFAULT"
]
}
],
"dataRoamingDisabled": true,
"kioskCustomLauncherEnabled": true
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml - 与管理接收器相关的部分
<receiver
android:name=".DeviceAdminReceiver"
android:lockTaskMode="if_whitelisted"
android:description="@string/admin_description"
android:label="@string/app_name"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/admin_permissions" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" …Run Code Online (Sandbox Code Playgroud) 我正在开发一个跟踪应用程序,并且需要防止用户关闭用于确定位置的基本传感器。我无法修改设备ROM或具有root用户访问权限(或者至少希望没有该用户访问权限),但是我想到了使用设备管理API通过概要文件所有者或设备所有者模式执行这些功能。我基本上是在寻找一种方法来阻止Android设置中的这些功能。
我不确定这是否可行以及如何实现,我没有在GitHub中找到实现此功能的应用程序示例。谁能给我一个简单的例子或特定的文档?
我试图遵循这三个文档,但没有成功找到针对此特定功能的解决方案:
https://source.android.com/devices/tech/admin https://developer.android.com/guide/topics/admin/device-admin https://developers.google.com/android/management/introduction
这是我一直在尝试的摘录:
setUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, true);
setUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, active);
setUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH, active);
private void setUserRestriction(String restriction, boolean disallow){
if (disallow) {
mDevicePolicyManager.addUserRestriction(mAdminComponentName, restriction);
} else {
mDevicePolicyManager.clearUserRestriction(mAdminComponentName,
restriction);
}
}
Run Code Online (Sandbox Code Playgroud)
DISALLOW_CONFIG_BLUETOOTH已在API级别18公共静态最终字符串DISALLOW_CONFIG_BLUETOOTH中添加
指定是否禁止用户配置蓝牙。这并不限制用户打开或关闭蓝牙。默认值为false。
此限制不会阻止用户使用蓝牙。要完全禁止在设备上使用蓝牙,请使用DISALLOW_BLUETOOTH。
此限制对托管配置文件无效。
用户限制的关键。
类型:布尔
android android-sensors device-admin device-owner android-enterprise
android ×10
device-admin ×10
apk ×1
certificate ×1
constructor ×1
cosu ×1
device-owner ×1
java ×1
kiosk ×1
kiosk-mode ×1
super ×1