Actually i want some kind of Broadcast when any other app fetches the data from the content provider shared by my app
Asked
Active
Viewed 4,613 times
2 Answers
13
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;
}

Rahul Tiwari
- 6,851
- 3
- 49
- 78
8
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.

Iria Somobu
- 79
- 1
- 7