Actually i want some kind of Broadcast when any other app fetches the data from the content provider shared by my app
you can use Binder.getCallingUid()
to get uid of calling application.
then use getPackageManager().getNameForUid(uid)
to get package name of calling app.
Example:
@Override
public Uri insert(Uri uri, ContentValues values) {
int code = sUriMatcher.match(uri);
String callingPackageName = getContext().getPackageManager().getNameForUid(
Binder.getCallingUid());
Log.d(TAG, "calling Package Name::" + callingPackageName);
if (callingPackageName.equals(PKG_MY_PACKAGE)) {
//do what you want
}
.
.
.
return uri;
}
Maybe I'm pretty late, but in API19 and above you can just call
getCallingPackage();
inside your ContentProvider to do this trick.
Look at Android Reference for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With