以管理员身份运行Android应用

时间:2011-11-11 23:27:31

标签: android admin manifest

我正在尝试编写一个简单的应用程序,并按照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:ERROR / AndroidRuntime(553):   java.lang.RuntimeException:无法实例化活动   ComponentInfo {com.appname.manager / com.appname.managerActivity $控制器}:   java.lang.InstantiationException:   com.appname.managerActivity $控制器

1 个答案:

答案 0 :(得分:1)

除非它是静态的,否则无法从其封闭类的外部创建嵌套类。将您的活动移至独立类(即未嵌套),或将活动类设为静态。