英文:
Check if Parental control is active on Amazon device
问题
我正在尝试找到一种检查亚马逊设备上是否启用了家长控制的方法。
我已经尝试了这段代码:
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(
Context.DEVICE_POLICY_SERVICE);
// 这个活动管理员是
// com.amazon.tv.parentalcontrols/com.amazon.tv.parentalcontrols.PCONAdminReceiver
boolean isActive = devicePolicyManager.isAdminActive
(devicePolicyManager.getActiveAdmins().get(0));
但这并不起作用,即使家长控制被禁用,isActive 始终为 true。
是否有一种使用标准权限来实现这一目标的方法?
英文:
I'm trying to find a way to check if parental control is enabled on an Amazon device.
I've tried this code
DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(
Context.DEVICE_POLICY_SERVICE);
//this active admin is
//com.amazon.tv.parentalcontrols/com.amazon.tv.parentalcontrols.PCONAdminReceiver
boolean isActive = devicePolicyManager.isAdminActive
(devicePolicyManager.getActiveAdmins().get(0));
But this doesn't work and isActive is always true even when Parental Control is disabled.
Is there a way to achieve this with standard permissions?
答案1
得分: 0
Hmm, 老实说,我不知道亚马逊如何实施家长控制。但只有两个想法,也许有助于前进一步:
- 在给定的代码中,您调用活动管理员的列表,然后检查第一个管理员是否处于活动状态。从逻辑上讲,您的
isActive
始终为真,因为您检查的isAdminActive
是一个只包含已激活管理员的列表项。但是,如果没有提供活动管理员,这个过程也应该引发错误,因为结果为null
值不允许在isAdminActive
上。 - 您是否检查了亚马逊是否真的使用设备管理员的激活?我可以想象,他们只会在您的设备上注册一个 'amazon' 管理员,然后在自己的代码中处理家长访问权限。这可能意味着 Android 亚马逊管理员始终处于活动状态,不管您在亚马逊中设置了哪些权限。
英文:
Hmm, honestly i don't know how Amazon implements the parental control. But just two thoughts, maybe it helps a bit to get forward:
- In the given code, you call the list of active admins and then check, if the first admin is active. Logically, your
isActive
is always true, since you checkisAdminActive
on a list-item out of only activated admins. However, this procedure should also throw you an error if there are no active admins given, since the resultingnull
value is not allowed onisAdminActive
. - Did you check, if Amazon does really use the activation of device admins? I could imagine, that they just register one 'amazon'-admin on your device, while then handling the parental access within their own code. This could mean, that the android-amazon-admin is just always active, no matter which rights you set within amazon.
答案2
得分: 0
你可以尝试这段代码
import android.provider.Settings;
public class ParentalControlChecker {
public static boolean isParentalControlEnabled() {
ContentResolver contentResolver = context.getContentResolver();
int parentalControlSetting = Settings.Secure.getInt(contentResolver, "parental_control_enabled", 0);
return parentalControlSetting == 1;
}
}
请记得更新你的 AndroidManifest.xml 文件以获取所需的权限:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
如果家长控制已启用,方法 isParentalControlEnabled() 将返回 true;否则,它将返回 false。
英文:
You can try this code
import android.provider.Settings;
public class ParentalControlChecker {
public static boolean isParentalControlEnabled() {
ContentResolver contentResolver = context.getContentResolver();
int parentalControlSetting = Settings.Secure.getInt(contentResolver, "parental_control_enabled", 0);
return parentalControlSetting == 1;
}
}
Keep in mind to update your AndroidManifest.xml file with the required permissions:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
If parental control is enabled, the method isParentalControlEnabled() will return true; otherwise, it will return false.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论