2

我正在使用以下代码启动要求用户授予应用程序、设备管理员状态的活动。

        mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
        try {
            mDeviceAdminSample = new ComponentName(this, WatchDogAdmin.class);
        } catch (Exception ex) {
            // TODO Auto-generated catch block
            Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
        }  

        Intent intent2 = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
//        Intent intent2 = new Intent(this, ShuntActivity.class);
        intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent2.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminSample);
        intent2.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "Device admin rights are required for this application to work correctly.");
//        startActivityForResult(intent, RESULT_ENABLE);
        startActivity(intent2);

我究竟做错了什么 ?没有错误,活动根本没有启动。

4

2 回答 2

0

确保WatchDogAdmin是接收器并尝试startActivityForResult(intent2, 1);

于 2012-09-16T06:45:12.623 回答
0

尝试删除线,

intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
于 2012-06-13T21:47:32.190 回答