Problems sharing data between different android applications - android

I´m currently trying to share information between different applications in Android, the goal I´d like to achieve is having the same behavior the KeyChain data share have in iOS but in Android.
I´ve already given a try using SharedPreferences and using "shareUserId" attribute inside Manifest, (by default Android applications behave as sandBoxes and they are not allowed to share data, they also haven´t a common context, so a "fake" one must be built) issues here come by the fact that is mandatory to know every app´s packageName so the data share happens between those apps with the same shareUserID value. I mean, I would like to access this resources without having to ask for the application that stored them.
Context appOne = createPackageContext("com.xxx.zzz.appOne", CONTEXT_INCLUDE_CODE);
mSharedPref = appOne.getSharedPreferences("Test", Context.MODE_PRIVATE);
Other way I tried was using the AccountManager in order to store that information so other applications could reach it. Bad news were that this account will be shared among all applications installed in the system and i will like this behavior to be more restrictive in terms that I would like to be able to choose which apps will have access to this information and those who won´t.
Reference to related post
(Should you use AccountManager for storing Usernames and Passwords for an Android app?)
Is there anyway to achieve this goal? Any help or hint will be appreciated, been stuck in here for a couple of days... If extra information is needed feel free to ask for it. Thanks in advance.

Related

Data storage option that best suits for my android app purpose

I am creating an android app that can be used by common users and also admin.
Suppose, if admin adds a new place name, that name should be added to database and when common user uses the app, he should be able to see the place name that is added.
I used MySqlLite database. But the problem is that if the app is uninstalled all data is lost. So I want some persistent data storage in which all the places that are added by admin are saved permanently.
Regards,
Sindhu
With the data being needed across multiple devices, your only option is to create/use a backend API.
Parse would have been a good choice but since that is getting shut down soon then it wouldn't be wise to use that.
Take a look at these alternatives here
You could also write one yourself, but unless you have some experience in that sort of thing then it will take some time to learn.

Sharing progress data between Android apps

I've nearly finished writing a game for the Android market. I have a full version and a free version with half the levels. I’ve read of a lot of people in similar situation with the following problem but can’t find a satisfactory solution:
My apps are separate but I want them to share data. At least I want the full version to be able to read the free version’s progress data. If a user finishes the free version, then installs the full, it needs to access the progress info because the first stage of the game is identical to the free version and the progress should be shared/mapped.
From what I have read the best way to save game progress is using SharedPreferences, which is what I’m doing and it’s working perfectly.
On searching for ways to share data I read that the best thing to do is to define the same android:sharedUserId in both AndroidManifest.xml files to be the same value and to ensure both apps are signed with the same key:
What is sharedUserId in Android, and how is it used?
multiple apps, sharing same data directory
I’ve done this and checked it’s working by using ApplicationInfo to see both app’s uids, which are the same. However, I was then expecting to be able to read and write to SharedPrefs from both apps (running at different times) and to be reading/writing the same data. But alas no. If this does not make the apps share the same SharedPreferences, then what data are they sharing by specifying the same sharedUserId?
After some more digging some people seem to be saying I need to access the other app’s context first:
http://thedevelopersinfo.com/2009/11/25/getting-sharedpreferences-from-other-application-in-android/
Can't read SharedPreferences fron another application
So if I want App2 to access App1's data, this gives me the following code in App2’s Activity:
Context otherAppsContext = null;
try {
otherAppsContext = createPackageContext("com.example.app1package",0);
} catch (NameNotFoundException e) {
}
SharedPreferences sharedPrefs = otherAppsContext.getSharedPreferences("TestShareData",Context.MODE_PRIVATE);
But when I ask sharedPrefs for data it still just gives me data from the current app (App2 instead of App1).
Inspecting the otherAppsContext variable I’m not sure what it’s giving me. It has an mBasePackageName property which is the package name of App2 (wrong). But it also has an mPackageInfo property which appears to contain data about App1.
I just don’t know if I’m doing things the right way but am missing something or if this isn't the way to go at all. I just want to link my 2 apps in such a way that one can read the other’s SharedPrefs. How do most full versions of apps link to the free one's data?
Any help would be greatly appreciated!
Sure this happens a lot but think I may have solved my own problem.
Both of my apps (full and free versions) are writing to sharedPrefs under the same name:
SharedPreferences settings = getSharedPreferences( PREFS_NAME, 0 );
Where PREFS_NAME is the same for both apps. When I ask for App1's Context from App2 it gives me a Context but it seems it's a Context that can access both Apps' data?
To explain when I get a Context for App1, from App2 and ask for SharedPreferences giving the name PREFS_NAME, I get the SharedPrefs from App2 instead. But I tried changing the SharedPrefs name for App1 and then accessing that from the context in App2 and suddenly it picks up App1's data.
I don't really know what I'm getting back from the createPackageContext call, it seems to be a handle to both sets of data. But I think I can just make my apps use different names for the SharedPrefs and have the full app just search for the free app's data if it needs to.

How to share data among applications when we don't know which app is provider but first app has stored data

I have 5(any number) android applications which will share some data.
Now when 1st/2nd/3rd..(i couldn't know) android application will get installed by user, it will save a string in the memory(internal memory),
When any other application will get installed, it should know that one of the app has already written data and now it should act as user of this data.
To sum up, first app installed will act as provider and others as users...but all the applications can be potential provider and other as users..
Is this feasible?
i tried using file/shared preference/content providers...but in file, you should know file path before using it which is dependent on package name..
In shared preference, we have to create package context..
In content provider, we have to import provider package..
My real motive is, actually in each app, i register the user first time...
now i want , if user install 2nd app from me, it can just use data of first app and do not ask for register..
but the problem is i don't know which app will be installed first by user..
Please help if i can use some other approach??
i found one thread related to this...
https://groups.google.com/forum/?fromgroups=#!topic/android-developers/W-oOa0x9amg
http://android.bigresource.com/Android-How-to-share-data-between-applications-with-no-dependency-HRMMGMIkL.html
This thread pretty much answers my question, in terms of feasibility and options i have for this scenario.

iOS/android hybrid app distribution/architecture model help or advice please

I am pretty new to the mobile end of development so forgive my naivety.
I would like to know if it's possible to have a structure/distribution model like the following:
Master App (has many "middle-man" instances)
!
!
Middle-man ( can customize data, look & feel, via web app and redistribute)
(has many end user viewers)
!
!
!
End User viewers( can download and install middle-man abc's app with middle-man's custom info)
Is this possible? I have searched around for quite a bit but perhaps I am searching the wrong terms?
I was thinking perhaps a couple options, let me know if it's sounds wrong.
Option 1 - Middle-man provides a special key code and end user types it in after installing the app to unlock it thereby storing the unique middle-man ID and displaying only their custom info. User only needs to enter code once. relation is stored in mysql perhaps??
Option 2 - create a build of the master template for each middle-man and provide the binary/install link along with a customized ini file to load correct ID? Or something to that effect.
Any better options out there? Something that allows for upgrades/new features to be passed down to all the instances easily.
Will this type of thing have any problems with the apple store if multiple middle men decide they want it on the app store?
Maybe I'm making it more complex than needed and could just use a simple "require login" for each end-user and the end user is tied to that middle man some how?
\The app could also be android app depending on middle-man requirements
Thanks in advance for any advice or links to helpful info.
If i had understood your question right, its a straight forward mobile app tied up with the backend.
User credentials for the middleman which shall associate with your
special key code.
Associate your actors(users) with roles and permission over accessing
content in the backend.
Your mobile app will pull the content only associated for the logged
in user.
Apart from this, you can store the content for offline etc.. Take phonegap approach and it pretty much does what you wanted to do.

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.

Categories

Resources