Creating event in calendar only once when App is installled - android

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.

Related

how to save my app preference and retrieve them after re-install or change of device

I'm new to app dev...
I read somewhere in the doc: "...In most cases you want to use SharedPreferences as it is automatically backed up and migrated to new devices..."
On first install my app saves a few settings with SharedPreferences. It works great but if I uninstall the app or install it on another device the preference settings are lost.
How can I have these settings saved online within google somehow to be able to retrieve them if the user changes his phone or similar...
Could someone point me in the right direction ?
I read somewhere in the doc: "...In most cases you want to use SharedPreferences as it is automatically backed up and migrated to new devices..."
Your words "backed up and migrated to new devices" is nowhere written nor its true.
We use SharedPreferences in order to minimise the database operations, its like keeping variables handy.
On first install my app saves a few settings with SharedPreferences. It works great but if I uninstall the app or install it on another device the preference settings are lost.
If you wants to store or remember the device dependent settings, use device id / imei_id and store it on your web server mysql database
Even if user uninstalls app from the device and installs again anytime in future, make a call with async task to server by sending deviceid / imei_id and fetch its settings from mysql database and show it.
How can I have these settings saved online within google somehow to be
able to retrieve them if the user changes his phone or similar...
If user changes device, you can do nothing.
One way is, keep public device_id levels keys on server.
If user changes device and uses that key, then show him a response, this key is assigned to another device, but if you are the same, wait for our support
Call him, confirm he is the same old user with new device and delete his old entry from mysql and assign old key to the new device entry
Or use OTP SMS system to identify already existing customers with unique phone numbers
If OTP authentication code is correct then fetch settings for that user from the server, delete old mysql entry, modify new entry with old key and mobile number
This should be the your direction
Edit : 2 ##
I was hoping an easier solution exist but....
There is no short cuts for developers till the date, and it will be never.
Why, no short cuts / easy ways ?
Any device ( mobile, desktop / laptop / any AI device ) which is operated by a system software, is able to perform the tasks as per it is structured.
Ex : android is java based, obviously you can Make javascript based apps, but it is the extensions to the existing system, Android still has the base of Java virtual machine. ( Dalvic / Malvic like )
So, it is always better to use native java
Yes, Kotlin is best option now a days and better than hybrid approach
Every way has its own advantages, disadvantages
If you are developer, should go with native approach
Now your java code never knows, which version it is running on, so you have to, check android versions programming wise, and decide the flow for above Marshmallow & below marshmallow too, and it is explicitly done by developer by coding.
Ex, once user registers, he never shown please register again screen, it is not the magic, nor google, nor, java, nor android does anything, developer has decided, planned, architectured, designed, coded, tested that.
Even developers needs to take care of exceptions, you need to handle it in order to save your app from crashing.
In short developer is god, who creates his own universe, and everything is pre-planned and verified thats it.
You should use allowBackup = "true" in your manifest file. More details can be found here: AutoBackup

Xamarin.Forms app need to write to a shared local storage location

I am in the process of writing a Xamarin.Forms line-of-business application.
The app will be targeting UWP and Android.
I have a requirement of being able to store information and pictures taken, in a shared folder on the local storage. This way, multiple users of the same device at different times can resume work-in-progress of the first user.
I am not sure what my options are, as I am unable to write outside of AppData folder (for UWP).
I read about potentially using a Picker and storing the selected folder in the FutureAccessList for UWP, but I am unsure if it will actually work and seems hacky as I will need to come up with a way of doing the same for Android at a later time.
Any ideas/pointers are greatly appreciated!
There is a special ApplicationData.SharedLocalFolder folder that allows you to share app data across user accounts on a PC. Its main limitation is that it requires appropriate Group Policy:
SharedLocalFolder is only available if the device has the appropriate group policy. If the group policy is not enabled, the device administrator must enable it. From Local Group Policy Editor, navigate to Computer Configuration\Administrative Templates\Windows Components\App Package Deployment, then change the setting "Allow a Windows app to share application data between users" to "Enabled."
I feel that the fact that this is not allowed by default is a great obstacle to the usefulness of this API.
There a publisher cache folder, but this solution is not appropriate for you because of documentation says:
Publisher Cache shares data across apps for the current user
So I would probably really go with the picker-based solution you proposed. Offer the user to select a folder to save the data to using the FolderPicker and then store the selected folder to the FutureAccessList. The future access list is reliable and can even track the changes of the selected item (like when the user moves it to a different location). The abstraction of the selection process in a cross-platform manner may be a bit more complicated, but it should be possible to hide it behind a dependency service implementation. My guess will provide an async method that will initialize the target location. On UWP this will check the FutureAccessList if a location was selected previously and if it was not, it will use the FolderPicker to let the user select it and will store it for future user afterward. On Android, it will work in Android specific manner (I am not sure what are the options there). Then the service will have some file manipulation methods that will abstract the platform-specific manipulation with the folder (I think you cannot use the common System.IO namespace, as you cannot directly access the user selected folder outside of the StorageFolder API)

Permanent access to app of dropbox account?

I have an app which links to an dropbox account. I am able to login once and is saves that. But each time it asks whether I want to allow access to the app or not . Is there a way to save this preference as well and provide access to the app permanently ?
Read again https://www.dropbox.com/developers/start/authentication#android especially "Return to your app after user authorization".
After successful .getSession().finishAuthentication() there is AccessTokenPair tokens = mDBApi.getSession().getAccessTokenPair() which will give You data, which You should save somewhere for later use (You can use SharedPreferences for this).
In start time of application You have to check existance of this saved data, and if it's there, You don't have to call .startAuthentication() again, instead You should call .setAccessTokenPair(access) with saved data as access (look at top of https://www.dropbox.com/developers/start/files#android ).

The easiest way to pass data between application in Android

What's the easiest way to pass data(string value) between two android applications with less or even without permissions? Also in my case first application sends data to un-existed application which is installing and it can't listen for intent right now.
Thanks.
Your question is tricky when you can't ensure that both applications are running. In cases like that, you must rely on some form of persistent storage.
If you're concerned with only a small amount of data, Android provides a SharedPreferences class to share preferences between applications. Most notably, you can add a OnSharedPreferenceChangeListener to each application so they can be notified when the other changes the value.
You can find more information on various different forms of persistent storage on the Android website (http://developer.android.com/guide/topics/data/data-storage.html).
So as you are mentioning intent and extras put to it is the way to go.
If you want to let an application receive data even if it's still installing there is no straight-forward way.
One way is as follows:
In the receiver-part of your code, send a received successfully-extra to the sender-application. If the sender-application does not get the received successfully-message after some time, store the data and wait until the application is installed. you may store this data on sd-card and let the other application read that on first use.
you can also do a check if the application is installed with PackageManager.

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