我正在尝试在我的应用中使用设备管理API。
我的 DeviceAdmin来电类是:
public class DeviceAdminCaller extends Activity {
static final int activationCode = 47;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
ComponentName deviceAdminComponent = new ComponentName(this, DeviceAdmin.class);
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, deviceAdminComponent);
intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, "We recommend you to enable this");
startActivityForResult(intent, activationCode);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case activationCode:
if (resultCode == Activity.RESULT_OK) {
Log.i("DeviceAdminSample", "Administration enabled!");
} else {
Log.i("DeviceAdminSample", "Administration enable FAILED!");
}
return;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
我的 DeviceAdminReciever 的子类是这样的:
public class DeviceAdmin extends DeviceAdminReceiver {
@Override
public void onEnabled(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onEnabled(context, intent);
Log.i("Device Admin", "Enabled");
}
@Override
public String onDisableRequested(Context context, Intent intent) {
// TODO Auto-generated method stub
return "Admin disable Requested";
}
@Override
public void onDisabled(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onDisabled(context, intent);
Log.i("Device Admin", "Disables");
}
@Override
public void onPasswordChanged(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onPasswordChanged(context, intent);
Log.i("Device Admin", "Password Changed");
}
}
包含DeviceAdmin 的清单部分是:
<activity
android:name=".DeviceAdmin"
android:label="activity_sample_device_admin" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity
android:name=".DeviceAdminCaller"
android:label="activity_caller_device_admin" >
<intent-filter>
<action android:name="android.intent.action.DEVICE_ADMIN_CALLER" />
<category android:name="android.intent.category.DEFAULT" />
<!-- <category android:name="android.intent.category.SAMPLE_CODE" /> -->
</intent-filter>
</activity>
<receiver
android:name=".DeviceAdmin"
android:permission="android.permission.BIND_DEVICE_ADMIN" >
<meta-data
android:name="android.app.device_admin_sample"
android:resource="@xml/device_admin_sample" />
<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>
LogCat输出为:Administration enable FAILED!
我做错了什么?我今天有一个项目提交。任何帮助,将不胜感激 。 :)
答案 0 :(得分:0)
我做错了什么?
您正在致电startActivityForResult()
,要求Intent
不支持该行为的RESULT_CANCELLED
行动。在这些情况下,您始终返回<h1>Hello {{name}},</h1>
<h1>Welcome to my website!</h1>
<h1>Please enter your name:</h1>
<input type="text" ng-model="name">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
。