以管理员身份运行 Android 应用程序

发布于 2024-12-15 05:53:37 字数 2486 浏览 2 评论 0原文

我正在尝试编写一个简单的应用程序,并遵循 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软的没边 2024-12-22 05:53:37

嵌套类不能从其封闭类的外部创建,除非它是静态的。将您的活动移至独立类(即非嵌套),或使活动类静态。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文