I have an application say A that have all the permissions enabled at installation. Another app Say B don't have a permission and want to get that permission. Can B communicate with A, So that A can transfer its permission to B.
PLS reply, I'm stuck here. I want to get some permissions dynamically. Is this the best idea or any other idea?
As far as I know, apps can't necessarily give permissions to other apps, BUT AppB could inherit permissions from AppA IF you are the developer of both apps. If both AppA and AppB declare the same sharedUserId value in their manifest (android:sharedUserId="xyz") AND both AppA and AppB are signed with the same signature, then Android will consider them to be the same app as far as permissions go. So, AppB could exist on the device without permission "perm1" for example. Then, AppA could be installed with "perm1". IF AppA and AppB have the same sharedUserId and signature then, when AppA is installed, AppB will be "granted" "perm1".
I haven't tested this just now, but I know it used to work (as of a year ago or so).
That would be quite in-secure, don't your think, if an application could give any permissions to another application...
Some evil-doer would just have to convince you to install his A application ; and, then, no matter what other B application you'd install, that B application wouldn't have to request any specific permission at installation (those would later be granted by A) -- and B would still be able to do anything on your device ?
I sure hope what you're asking is not possible ;-)
Your application A can provide some Content Providers to access information. Application B could use the content provider of A to gain the information. http://developer.android.com/guide/topics/providers/content-providers.html
But somehow this sounds like you want to do something evil. If you like to have more information please provide more about your need to do that!
Yes this is possible in a roundabout way using PendingIntents. This is not an exact code snippet but should give you the idea:
You cannot transfer the permissions, but you can transfer capabilities to perform certain actions from A to B. Let's say you want to transfer the capability of executing a certain ACTION
.
A needs to create a pending intent:
Intent intent = new Intent(ACTION);
PendingIntent pIntent = PendingIntent.getActivity(context, requestCode, intent, flags);
A sends this to B by marshalling the pending intent
Intent intent = new Intent(context, B.class);
intent.putExtra("pendingIntent", pIntent);
startActivity(intent);
At B we deserialize the pending intent and we can use it to perform the restricted ACTION
PendingIntent pIntent = intent.getExtra("pendingIntent");
pIntent.send();