Java android中是否有安装事件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2227604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:58:40  来源:igfitidea点击:

Is there on install event in android?

javaandroid

提问by Dmytro

Is there some event/receiver or something for handling first execution after installation or directly after installation? Or Do I need it emulate with preferences?

是否有一些事件/接收器或用于在安装后或直接在安装后处理第一次执行的东西?或者我需要它模拟偏好吗?

采纳答案by Dave Webb

There is the ACTION_PACKAGE_ADDEDBroadcast Intent, but the application being installed doesn't receive this.

ACTION_PACKAGE_ADDED广播意图,但正在安装的应用程序没有收到这个。

So checking if a preference is set is probably the easiest solution.

因此,检查是否设置了首选项可能是最简单的解决方案。

SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this);
boolean firstRun = p.getBoolean(PREFERENCE_FIRST_RUN, true);
p.edit().putBoolean(PREFERENCE_FIRST_RUN, false).commit();

回答by Denys Séguret

I don't think there is such a thing, and I don't think this would be a good idea : usually you have to handle not only installations but some updates (say : a new version with features) or the proper initialization of some resources.

我不认为有这样的事情,而且我认为这不是一个好主意:通常,您不仅要处理安装,还要处理一些更新(例如:具有功能的新版本)或正确初始化某些资源。

For the resources, the best way is to check them directly.

对于资源,最好的方法是直接查看它们。

For the version, I use the database, it's so easy.

对于版本,我用的是数据库,就这么简单。

回答by cdonner

The SQLiteOpenHelper's OnUpgrade method is called when the database version changed. I suppose this could be used to do other things than just handling the new schema.

SQLiteOpenHelper 的 OnUpgrade 方法在数据库版本更改时被调用。我想这可以用来做其他事情,而不仅仅是处理新模式。

回答by Kenton Price

See Get referrer after installing app from Android Market- you can put whatever you want in there. I believe this is how Plan Bworks - the app that can send back your phone's location after it's stolen, that you install from the website afterit's been stolen.

请参阅从 Android Market 安装应用程序后获取引荐来源- 您可以在其中放入任何您想要的内容。我相信这就是Plan B 的工作方式 - 可以在手机被盗后发回手机位置的应用程序,您可以在手机被盗从网站安装该应用程序。