如何启用和禁用组件?组件

由网友(专属↘嗳)分享简介:我最初的问题是基本上沿此线的东西:Clearing并设置默认主页应用程序(解决) My initial question was basically something along the lines of this: Clearing and setting the default home application...

我最初的问题是基本上沿此线的东西:Clearing并设置默认主页应用程序(解决)

My initial question was basically something along the lines of this: Clearing and setting the default home application (SOLVED)

这问题得到回答让我满意的,但是,我有在答题难度理解的是你怎么能够再从清单在java code禁用成分?

That question was answered to my satisfaction, however, the thing I'm having difficulty understanding in the answer is how do you enable and then disable a component from the manifest in the java code?

推荐答案

通过使用包管理器,你可以启用或menifest文件中禁用组件声明 有两个标志PackageManager.COMPONENT_ENABLED_STATE_DISABLED为使组件禁用组件和PackageManager.COMPONENT_ENABLED_STATE_ENABLED。

By using package manager you can enable or disable component declared in menifest file There are two flag PackageManager.COMPONENT_ENABLED_STATE_DISABLED for disable component and PackageManager.COMPONENT_ENABLED_STATE_ENABLED for enable component.

   PackageManager pm  = getApplicationContext().getPackageManager();
   ComponentName componentName = new ComponentName("com.app",
         ".broadcast_receivers.OnNetworkChangedReceiver");
      pm.setComponentEnabledSetting(componentName,
        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP);

Android清单:

Android manifest:

<receiver android:name=".broadcast_receivers.OnNetworkChangedReceiver"
            android:enabled="true">
        <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
        </intent-filter>
</receiver>
阅读全文

相关推荐

最新文章