安装更新后的Android重新启用已禁用的应用 [英] Android re-enable a disabled App upon installation of update
问题描述
即时通讯目前是禁用通过一个应用程序
setApplicationEnabledSetting(字符串,INT,INT)
Im currently disabling an application via setApplicationEnabledSetting(String, int, int)
应用程序实际上是禁用本身。
我希望在应用程序的重新安装,应用程序将重新启用本身,但是这个心不是这样的。
The application is actually disabling itself. I would expect upon re-installation of the app, the app would re-enable itself, however this isnt the case.
有没有在清单中,使这项工作需要特殊设置。
(伊夫尝试设置启用= TRUE)
Is there a particular setting required in the manifest to make this work. (Ive tried setting enabled=true)
感谢
即时通讯目前禁用所有组件除了广播接收器,我试图抓住安装过程中重新启用所有其他组件。这是讨厌的,至少可以说
Im currently disabling all components apart from a broadcast receiver and am trying to catch the installation process to re-enable all the other components again. Which is nasty to say the least
推荐答案
要做到这一点的方法之一是听包安装广播和采取相应的行动。
One way to do this is to listen to package installation broadcasts and take action accordingly.
- 接听
Intent.ACTION_PACKAGE_ADDED
在您广播接收机。 - 如果新加入的包是你的,让其他组件。
清单:
<receiver android:name =".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<data android:scheme="package" />
</intent-filter>
</receiver>
接收器:
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {
final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
final String packageName = intent.getData().getSchemeSpecificPart();
if (replacing && "my.package.name".equals(packageName)) {
// Re-enable the other components
}
}
}
}
希望这有助于。
这篇关于安装更新后的Android重新启用已禁用的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!