简体   繁体   English

如何在 Android App 中记录按钮点击

[英]How to keep a log of button clicks in Android App

I have an App in which I would like to start charging the user after they use a feature 5 times.我有一个应用程序,我想在用户使用一项功能 5 次后开始向他们收费。

The unpaid App allows the user to click a button (to do a pre-determined task), and after that, the user must pay to be allowed to do the same task again.无偿App允许用户点击一个按钮(做一个预定的任务),之后,用户必须付费才能被允许再次做同样的任务。

I need to make sure that the log of button clicks is saved even when the user uninstalls/then re-installs the app - this is the main thing I do not know how to do.即使用户卸载/然后重新安装应用程序,我也需要确保保存按钮点击日志 - 这是我不知道该怎么做的主要事情。

Please kindly help!请帮助!

first get the device unique ID with:首先通过以下方式获取设备唯一 ID:

String id = Secure.getString( 
       getContext().getContentResolver(),
                   Secure.ANDROID_ID);

then store this id on your server with number of clicks, so every time the user redownloads your app you can identify the device and check how many times the user clicked the button然后将此 ID 与点击次数一起存储在您的服务器上,因此每次用户重新下载您的应用时,您都可以识别设备并检查用户点击按钮的次数

Well, if you want to keep this info even if the user reinstall the app, you can't save this info in local storage.好吧,如果您想在用户重新安装应用程序的情况下保留此信息,则无法将此信息保存在本地存储中。 You should have a database where you can store a user ID and how many times user has already clicked.您应该有一个数据库,您可以在其中存储用户 ID 以及用户已经点击了多少次。

As creating a database and put it online requires some backend work, if you have no backend skills (like me), give it a try to firebase: https://firebase.google.com/由于创建数据库并将其上线需要一些后端工作,如果您没有后端技能(如我),请尝试 firebase: https://firebase.google.com/

In short words, firebase is a Google solution to provide a backend to your app.简而言之,firebase 是一种 Google 解决方案,可为您的应用程序提供后端。

With firebase you'll be able to apply a login system (where you'll have a user ID) and create a dabatase (where you can store infos, like how many times user has used the feature)使用 firebase,您将能够应用登录系统(您将拥有一个用户 ID)并创建一个数据库(您可以在其中存储信息,例如用户使用该功能的次数)

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

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