import androID.app.Activity;import androID.app.admin.DevicePolicyManager;import androID.content.Componentname;import androID.content.Intent;import androID.os.Bundle;import androID.util.Log;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.Toast;import com.Google.androID.gms.common.GooglePlayServicesUtil;public class Registeractivity extends Activity { // alert dialog manager AlertDialogManager alert = new AlertDialogManager(); // Internet detector ConnectionDetector cd; // UI elements EditText txtname; EditText txtEmail; // Register button button btnRegister; static final int ACTIVATION_REQUEST = 47; //Request ID for Device administrator @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_register); //Unrelated int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); if (status != 0) { Toast.makeText(this,"This device is not supported - please download Google Play Services.",Toast.LENGTH_LONG).show(); } //Begin enabling device administrator Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_admin); Componentname deviceadminComponentname = new Componentname(this,Deviceadmin.class); intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_admin,deviceadminComponentname); intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,"You must enable device administration for certain features" + " of the app to function."); //I thought that this would start the activity that lets the user //choose whether to enable the app as a device admin startActivityForResult(intent,ACTIVATION_REQUEST); //Also contains code pertaining to unrelated Google Cloud messaging features //and an onClick() method,all insIDe of onCreate() }@OverrIDeprotected voID onActivityResult(int requestCode,int resultCode,Intent data) { switch (requestCode) { case ACTIVATION_REQUEST: if (resultCode == Activity.RESulT_OK) { Log.i("DeviceadminSample","administration enabled!"); } else { Log.i("DeviceadminSample","administration enable Failed!"); } return; } super.onActivityResult(requestCode,resultCode,data);}
使用此代码,当我运行我的应用程序时,活动出现,然后有动画,它看起来正在打开一个新活动,但然后该动画停止并保持当前活动而不提示用户启用设备管理.我的所有关于设备管理员的日志消息都没有被点击.但是,在Settings-> Security->设备管理员页面上查看当前的设备管理员时,我的应用程序会显示但是作为设备管理员取消选中.
这是我的Deviceadmin子类的代码,虽然我无法在此代码中看到问题的来源:
import androID.app.admin.DeviceadminReceiver;import androID.content.Context;import androID.content.Intent;import androID.util.Log;public class Deviceadmin extends DeviceadminReceiver { @OverrIDe public voID onEnabled(Context context,Intent intent) { super.onEnabled(context,intent); Log.i("Device admin: ","Enabled"); } @OverrIDe public String ondisableRequested(Context context,Intent intent) { return "admin disable requested"; } @OverrIDe public voID onDisabled(Context context,Intent intent) { super.onDisabled(context,"Disabled"); } @OverrIDe public voID onPasswordChanged(Context context,Intent intent) { super.onPasswordChanged(context,"Password changed"); }}
任何帮助将不胜感激!
更新:AndroID Manifest中的Device admin接收器如下:
<!-- Device administration Receiver --> <receiver androID:name="com.myPackage.DeviceadminReceiver" androID:permission="androID.permission.BIND_DEVICE_admin"> <Meta-data androID:name="androID.app.device_admin" androID:resource="@xml/device_admin" /> <intent-filter> <action androID:name="androID.app.action.DEVICE_admin_ENABLED" /> <action androID:name="androID.app.action.ACTION_DEVICE_admin_disABLE_REQUESTED" /> <action androID:name="androID.app.action.ACTION_DEVICE_admin_Disabled" /> </intent-filter> </receiver>解决方法 我猜你忘了用正确的意图过滤器在清单中添加接收器
<receiver androID:name="com.yourpackage.Deviceadmin" androID:permission="androID.permission.BIND_DEVICE_admin" > <intent-filter> This action is required <action androID:name="androID.app.action.DEVICE_admin_ENABLED" /> </intent-filter> This is required this receiver to become device admin component. <Meta-data androID:name="androID.app.device_admin" androID:resource="@xml/device_admin" /> </receiver>
和XMl
<device-admin xmlns:androID="http://schemas.androID.com/apk/res/androID" ><uses-policIEs> <limit-password /> <watch-login /> <reset-password /> <force-lock /> <wipe-data /> <expire-password /> <encrypted-storage /> <disable-camera /></uses-policIEs></device-admin>
有关设备管理的更多信息. Check this
总结以上是内存溢出为你收集整理的Android设备管理员权限活动未启动全部内容,希望文章能够帮你解决Android设备管理员权限活动未启动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)