Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Sharing data between Android framework and app
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Sihan Goi  
View profile  
 More options Aug 13 2012, 2:59 am
From: Sihan Goi <gois...@gmail.com>
Date: Mon, 13 Aug 2012 14:59:12 +0800
Local: Mon, Aug 13 2012 2:59 am
Subject: Sharing data between Android framework and app

Hi,

Is it possible to share data between the Android framework and an app?

I'm modifying the Android framework login component so that a variable will
be saved upon login, and then later retrieved by another app. I'm trying to
use SharedPreferences, and my code looks like this:

In com.android.internal.policy.impl.PasswordUnlockScreen.java, I have the
following code to write to the SharedPreferences.

SharedPreferences prefs = getContext().getSharedPreferences("mypref",
Context.MODE_WORLD_READABLE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("mypref", "my data"
editor.commit();

In my other app, I have the following code to read from it.

Context con;
String data;
try {
  con = this.createPackageContext("com.android.internal.policy.impl", 0);
  SharedPreferences pref = con.getSharedPreferences("mypref",
Context.MODE_PRIVATE);
  data = pref.getString("mypref", "0")

} catch (NameNotFoundException e) {

  data = "0";
  Log.e("No data shared", e.toString());

}

When I run the code, I keep getting the NameNotFoundException, as it claims
the application package com.android.internal.policy.impl is not found, so
my data is always "0".

How can I share data between these 2 components?

Thanks.

--
- Goi Sihan
gois...@gmail.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kristopher Micinski  
View profile  
 More options Aug 13 2012, 4:01 am
From: Kristopher Micinski <krismicin...@gmail.com>
Date: Mon, 13 Aug 2012 04:01:59 -0400
Local: Mon, Aug 13 2012 4:01 am
Subject: Re: [android-developers] Sharing data between Android framework and app
FYI this *definitely* does not belong on android-developers.

Additionally, it's sort of unclear what you're asking.  You're asking
about the sharing of the shared preferences, correct?...  If you're
modifying the system and can't figure, that generally doesn't bode
well.. What are you actually trying to do?  Something with
authentication?

kris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jan Burse  
View profile  
 More options Aug 13 2012, 4:11 am
From: Jan Burse <janbu...@fastmail.fm>
Date: Mon, 13 Aug 2012 10:11:48 +0200
Local: Mon, Aug 13 2012 4:11 am
Subject: Re: Sharing data between Android framework and app
You can store key/value pairs in Accounts, via the Account
Manager. I never did it, but I guess it could fit your needs,
since you anyway seem to plug-in into some Account
validation, right?

http://developer.android.com/reference/android/accounts/AccountManage...

See getUserData(), setUserData()

Sihan Goi schrieb:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
galapogos  
View profile  
 More options Aug 13 2012, 5:28 am
From: galapogos <gois...@gmail.com>
Date: Mon, 13 Aug 2012 02:28:06 -0700 (PDT)
Local: Mon, Aug 13 2012 5:28 am
Subject: Re: [android-developers] Sharing data between Android framework and app

Where would it belong then?

Yes I'm trying to share some data between the framework and the launcher
app, and I'm trying to accomplish this via SharedPreferences. The framework
will set a variable during user authentication, which will then be read
later on by the launcher. I'm having some problems doing this as I get a
NameNotFoundException exception in my try-catch block.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kristopher Micinski  
View profile  
 More options Aug 13 2012, 10:31 am
From: Kristopher Micinski <krismicin...@gmail.com>
Date: Mon, 13 Aug 2012 10:31:47 -0400
Local: Mon, Aug 13 2012 10:31 am
Subject: Re: [android-developers] Sharing data between Android framework and app
This group is solely for SDK related applications.  There is a list of
groups on the website indicating which might be good for this,
android-platform, and android-porting, perhaps?

I'm a little weary of sticking this in shared preferences for this,
but I guess there's nothing inherently horrible about that..

kris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
galapogos  
View profile  
 More options Aug 13 2012, 10:57 pm
From: galapogos <gois...@gmail.com>
Date: Mon, 13 Aug 2012 19:57:40 -0700 (PDT)
Local: Mon, Aug 13 2012 10:57 pm
Subject: Re: [android-developers] Sharing data between Android framework and app

Thanks, I didn't know of the android-platform group, I've posted my
question there.

Meanwhile, do you have any idea why I would encounter the above-mentioned
problems with SharedPreferences?

I've also tried simply creating a file in /mnt/sdcard in the framework with
the intention of the app reading it later, but I was thrown a permission
denied error. I was under the impression that accessing the external sdcard
required no special permissions, but if permissions are necessary, I'm not
even sure where to specify it since I can't seem to find the
AndroidManifest.xml of this particular framework component.

Thanks again.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
galapogos  
View profile  
 More options Aug 13 2012, 10:59 pm
From: galapogos <gois...@gmail.com>
Date: Mon, 13 Aug 2012 19:59:27 -0700 (PDT)
Local: Mon, Aug 13 2012 10:59 pm
Subject: Re: Sharing data between Android framework and app

Thanks. However, the device I'm working on doesn't have an internet
connection nor any accounts set up, so whenever I try to access the
accounts, even just accounts[0], I get a ArrayIndexOutOfBoundsException.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kristopher Micinski  
View profile  
 More options Aug 13 2012, 11:28 pm
From: Kristopher Micinski <krismicin...@gmail.com>
Date: Mon, 13 Aug 2012 23:28:19 -0400
Local: Mon, Aug 13 2012 11:28 pm
Subject: Re: [android-developers] Sharing data between Android framework and app
Well, this isn't really the appropriate place to answer system hacking
related questions, but basically, you're not running in the context of
that package, you're running somewhere else, so you're not storing in
that shared preferences.

But beyond that, this is just a horrible design, you're using a shared
preferences and then: you encode the component statically, leading to
a really kludgey hack depending on your system component, you allow
the string to be read by *anyone*, not just your app, which it
probably should be, and in reality sharing data to an app should
probably be shared by using a new system server and then interfaced
with via an AIDL component or something of the like, like *every
other* system process, that is the "standard" way.

You might be upset, because perhaps this is just a quick hack, but
then, that type of question doesn't belong on android-developers, and
this is what I think is the "right" way to do it :-).

You can see tons of other examples of this kind of thing: inside any
*Manager, for example, providing this interface.

kris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
galapogos  
View profile  
 More options Aug 14 2012, 2:10 am
From: galapogos <gois...@gmail.com>
Date: Mon, 13 Aug 2012 23:10:32 -0700 (PDT)
Local: Tues, Aug 14 2012 2:10 am
Subject: Re: [android-developers] Sharing data between Android framework and app

Thanks Kristopher,

I fully understand the kludgeyness of this implementation, and you're
absolutely right, this is a quick dirty hack. The actual implementation
will not be done in this way, but rather in a more secure location.
However, that portion is currently not being done by myself, so in the mean
time I'm trying to whip some sort of a framework up to continue development
and testing, and then port the final implementation over once that is
ready. It does not need to be secure or elegant - it just needs to work for
now, like a duct tape, which is why I'm even contemplating writing to a
file on the sdcard (which is totally insecure and not a good idea for a
final implementation). :)

In any case, I appreciate your continued patience in addressing my somewhat
esoteric problems.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »