以管理员身份运行 Android 应用程序
我正在尝试编写一个简单的应用程序,并遵循 ApiDemos 示例。我的应用程序在启动时崩溃。我怀疑我的清单有问题,但我不确定。有什么想法吗?
public class managerActivity extends DeviceAdminReceiver {
public class Controller extends Activity {
static final int RESULT_ENABLE = 1;
DevicePolicyManager mDPM;
ActivityManager mAM;
ComponentName mDeviceAdminSample;
Button mEnableButton;
Button mDisableButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mAM = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
mDeviceAdminSample = new ComponentName(Controller.this, managerActivity.class);
setContentView(R.layout.main);
}
}
然后在我的清单中,我有:
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="com.appname.managerActivity$Controller"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</activity>
<!-- Device Admin Samples -->
<receiver android:name="com.appname.managerActivity"
android:label="@string/sample_device_admin"
android:description="@string/sample_device_admin_description"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/device_admin_sample" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
这是崩溃:
11-11 15:20:52.310: 错误/AndroidRuntime(553): java.lang.RuntimeException:无法实例化活动 组件信息{com.appname.manager/com.appname.managerActivity$Controller}: java.lang.InstantiationException: com.appname.managerActivity$Controller
I'm trying to write a simple app, and follow the ApiDemos sample. My app is crashing on startup. I suspect a problem with my manifest, but I'm not sure. Any ideas please?
public class managerActivity extends DeviceAdminReceiver {
public class Controller extends Activity {
static final int RESULT_ENABLE = 1;
DevicePolicyManager mDPM;
ActivityManager mAM;
ComponentName mDeviceAdminSample;
Button mEnableButton;
Button mDisableButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mAM = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
mDeviceAdminSample = new ComponentName(Controller.this, managerActivity.class);
setContentView(R.layout.main);
}
}
and then in my manifest, I have:
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="com.appname.managerActivity$Controller"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</activity>
<!-- Device Admin Samples -->
<receiver android:name="com.appname.managerActivity"
android:label="@string/sample_device_admin"
android:description="@string/sample_device_admin_description"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data android:name="android.app.device_admin"
android:resource="@xml/device_admin_sample" />
<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
Here's the crash:
11-11 15:20:52.310: ERROR/AndroidRuntime(553):
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.appname.manager/com.appname.managerActivity$Controller}:
java.lang.InstantiationException:
com.appname.managerActivity$Controller
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嵌套类不能从其封闭类的外部创建,除非它是静态的。将您的活动移至独立类(即非嵌套),或使活动类静态。
The nested class cannot be created from outside of its enclosing class, unless it's static. Move your activity to a standalone class (i. e. not nested), or make the activity class static.