Check if user is really a first time user - android

I'm working on an Android app where everything is stored locally. (There is no account registration system). If a user tapped the Clear data and Clear cache option under Settings > Applications > Manage Application the on boarding process will show up again because the local storage got reset.
What options do developers have to check if a user is really a first time user and didn't just reset or reinstalled the app?

With server -
Send a unique device id to the server and save its state.
Without server (in your case) -
The only option for to save it after reinstall/clear cache is to add the permission to read/write sd card and hide it in the device where he wont delete it. I've hide it in data/data/my_package_name_backwords, be if i wouldnt do it backwords then the system deletes this folder when the user uninstall my app.

While I would advice against such an implementation, since users have the right to 'reset' the application and it is expected behavior to revisit the first launch screen, the following option would be feasible:
Use a web service and store the device id upon completing the first launch. When the application is launched, check if the device id is already present in the the database. For obtaining the device id, I would like to refer to this answer

Dont allow the user to clear the application data via ManageActivity. Allow the user to delete the data only through the app.
If the user clears the Data being inside the app, next time the user launches the app, will create the credentials and store it locally!
If you want the user not to clear the data by clearing the cache then create a dummy Activity that inturn lanuches your MainActivity and in the manifest declare this tag!
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:manageSpaceActivity="com.urapp.DummyActivity"
android:theme="#style/AppTheme" >
...
...
</application>
Thats it! Now, when the user tries to clear the data it will launch your MainActivity!

Related

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.
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.
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:
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
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.
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/
In short words, firebase is a Google solution to provide a backend to your app.
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)

Getting old data after reinstallation of my app in android

I am making an app where I am fetching data from a remote database and displaying it on google map. After the installation login page appears and after the credentials are verified google map appears with data fetched from database. I have saved login status and data in shared preference so that when user opens the app again after closing it it will not ask for login until user log out and also it will not ask for data until refresh button is clicked. On clicking refresh button I clear old data from preference and again save fresh data to it.
Now the problem is that whenever I uninstall and install app again I am not getting the login page and I am getting google map page with some old data.
Can anyone tell me why is this happening?
You may rarely face issue in older than Marshmallow version but you may face this issue in Marshmallow version because in Marshmallow all the app data are backed up. So first thing you need to set allowBackup as false in manifest as default is true so if you don't mention below code it will take it as true by default.
<application
android:allowBackup="false"
..
>
Then search for a folder in internal as well as external memory with the name as your app package name and delete it and restart your phone.
This will happen, when backup for the application is enabled in the manifest.
You can specify
<application
android:allowBackup="false"
... >
to disable this.

Creating event in calendar only once when App is installled

I am developing a Application which will create events in calendar. Events should get created only once when my application is installed and opened. I tried with using Shared preferences. But when i clear my app data, shared preferences were also getting cleared.
Please let me know how to do this.
Although Shared preferences is usually used for the use case like yours, but since you wants to be guarded against "Clear Data", You may create an empty file as an alternative.
You can check (before creating a Cal.event) if your file(whose exact name and location is only known to you) exist.
Obviously, there are many situations with this approach against which you need to protect.
1.what if user removes this file?
2.if you chose to save file on SD-card, what if sdcard is removed?
In case, if you do not want to rely on Device and data saved on device, and if your app can communicate with Server, then you can maintain this installation history information "online". Then, invoke a network call to query "installation history" info.
For this method to work, you also needs to track on which device and user, the installation was done previously.

Storing temporary values

I have to store value for temporary use so I used SharedPrefences for that but in this case when the user goes to Setting -> Application -> Application and then clicks on Force stop and Clear data then SharedPrefences is lost. So is there any suggest to solve this problem?
You can use element android:manageSpaceActivity in your AndroidManifest.xml to point to an activity. So when the user goes to the details page of your app in Settings, there will be a button Manage space instead of Clear data. Clicking that button will bring your specified activity up. Then you can show the user options to manage data (database, preferences…).
The only work around to fix this problem is to use a web service and store your data on the server. You can make device IMEI as primary key to avoid duplication.
as already mentioned above, the only proper way to prevent the user from having the possibility to delete your app data is storing the data on the web and download when needed. You can do both and then perform a check on runtime. If the required data is missing, then it gets downloaded

How do I know that an Android app has been loaded for the first time?

How do I figure out, if an app is loaded for the first time after it has been downloaded. I mean when the app is first bought/downloaded from market, how will I figure it that this is the first time(never has been run on this phone) this is going to run hence I can throw up some registration activity?
yeah, I thought of declaring a table which is checked to see if it has any rows. If there were rows then this was because it had been loaded and we inserted a row.
But I want to avoid this, is their any API which can tell me that the user had used this app before on this phone?
Android has API to store preferences.
You can store a flag in SharedPreferences, read about shared preferences
You can have a flag that you track, i.e. isFirstTime. Have a check in your main activity:
if(isFirstTime)
// do registration
isFirstTime = false;
You can save the value in between executions as a shared preference. See Data Storage documentation for details on how to do that.
Write a property somewhere that persists on the first load and check for that on every load, if it is there then you know that it has already been loaded once. Or you might even just make it a load counter and maybe you could use that information as a statistic (report back some where)
every application has it's own directory for data (/data/data/).
just write an empty file there and check for it every time you start an application
I don't know of any Android Market API that will tell you if the user downloaded/used the app before.
I think that you'll have to do it yourself which gives you two choices to persist data across an app uninstall/reinstall cycle:
(1) save a file on the SD card an check that to see if the app was installed before or
(2) contact a server with some user specific info to check if it was downloaded/used before.
The problem with the SD card method is that its not effective if the user erases the file or switches SD cards.
For the server model, you'll need to have a server to record some piece of information like user id or device id or some mix.

Categories

Resources