gpt4 book ai didi

android - 阻止 BroadCastReceiver 在 Android 中触发应用程序更新

转载 作者:行者123 更新时间:2023-12-04 23:58:12 26 4
gpt4 key购买 nike

当在设备中安装或卸载新应用程序时,我必须显示提示,到目前为止它工作正常。唯一的问题是即使更新应用程序也会提示。如何阻止 BroadCastReceiver 在应用程序更新时触发。

<receiver android:name=".WeepingReceiver">
<intent-filter android:priority="100">
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />

<data android:scheme="package" />
</intent-filter>
</receiver>

广播

@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_PACKAGE_INSTALL)
|| intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
context.startActivity(new Intent(context, NewAppActivity.class).
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK).putExtra(Utility.NEW_PACKAGE_NAME, packageName));
}

最佳答案

试试这个

Bundle extras = intent.getExtras();
if (extras.containsKey(Intent.EXTRA_REPLACING) && extras.getBoolean(Intent.EXTRA_REPLACING))
{
//do nothing here it is condition of updating your existing app
}else
{
//do your code here
}

关于android - 阻止 BroadCastReceiver 在 Android 中触发应用程序更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45504031/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com