简体   繁体   English

确定应用程序首次运行

[英]Determine application first run

I want to determine whether my application being run for the first time, and so it will be hard to pass around it. 我想确定我的应用程序是否第一次运行,因此很难传递它。

The preferences or empty file approaches are not going to work because you can simply clear the application data or delete the empty file. 首选项或空文件方法不起作用,因为您只需清除应用程序数据或删除空文件即可。

Also I want to do it offline so no server checking is going to work either. 此外,我想离线,所以没有服务器检查也可以工作。

Maybe it's possible to add some code to the installation of the apk so it will only run once. 也许可以在apk的安装中添加一些代码,这样它只会运行一次。

So my best bet is spawning a lot of empty files all around and hope the user won't find them, but this is pretty messy. 所以我最好的选择是产生大量的空文件并希望用户不会找到它们,但这非常混乱。

Has anyone ever done this somehow before? 有没有人曾经以某种方式做过这件事? Any suggestions? 有什么建议么?

The preferences or empty file approaches are not going to work because you can simply clear the application data or delete the empty file. 首选项或空文件方法不起作用,因为您只需清除应用程序数据或删除空文件即可。

One possibility is to have a BroadcastReceiver , registered in your manifest, that you do not actually use for anything. 一种可能性是在您的清单中注册一个您实际上并未用于任何事情的BroadcastReceiver On first run of your app, disable that receiver via PackageManager and setComponentEnabledSetting() . 首次运行应用程序时,通过PackageManagersetComponentEnabledSetting()禁用该接收器。 On future runs, you can determine if that BroadcastReceiver is already disabled via PackageManager and getReceiverInfo() . 在将来的运行中,您可以确定是否已通过PackageManagergetReceiverInfo()禁用了BroadcastReceiver

If the user uninstalls and reinstalls the app, the app will return to its original state. 如果用户卸载并重新安装该应用程序,该应用程序将返回其原始状态。 Rooted device users can also get past this. 有根设备的用户也可以通过这个。 Otherwise, this should be reasonably solid. 否则,这应该是相当坚实的。

I know you said you dont want files, but if you create them as local internal storage then the user can not delete them as they wont have access unless it is rooted phone. 我知道你说你不想要文件,但如果你把它们创建为本地内部存储,那么用户就无法删除它们,因为除非它是root用户手机,否则它们无法访问。 Clearing data "may" delete them. 清除数据“可能”删除它们。

There is another solution but it is lengthy one. 还有另一个解决方案,但它很冗长。 Use SQLite database.IT is local and I dont think it can be deleted otherwise the whole application will crash 使用SQLite database.IT是本地的,我不认为它可以被删除,否则整个应用程序将崩溃

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM