下面列出了android.os.Binder#getCallingUserHandle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressLint("NewApi")
private void notifyChange(final Uri uri) {
// If the calling user is different than current one, we need to post a
// task to notify change, otherwise, a system level hidden permission
// INTERACT_ACROSS_USERS_FULL is needed.
// The related APIs were added in API 17, it should be safe to fallback to
// normal way for notifying change, because caller can't be other users in
// devices whose API level is less than API 17.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
UserHandle callingUserHandle = Binder.getCallingUserHandle();
if (callingUserHandle != null
&& !callingUserHandle.equals(android.os.Process.myUserHandle())) {
ThreadUtils.postOnUiThread(new Runnable() {
@Override
public void run() {
getContext().getContentResolver().notifyChange(uri, null);
}
});
return;
}
}
getContext().getContentResolver().notifyChange(uri, null);
}
@SuppressLint("NewApi")
private void notifyChange(final Uri uri) {
// If the calling user is different than current one, we need to post a
// task to notify change, otherwise, a system level hidden permission
// INTERACT_ACROSS_USERS_FULL is needed.
// The related APIs were added in API 17, it should be safe to fallback to
// normal way for notifying change, because caller can't be other users in
// devices whose API level is less than API 17.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
UserHandle callingUserHandle = Binder.getCallingUserHandle();
if (callingUserHandle != null
&& !callingUserHandle.equals(android.os.Process.myUserHandle())) {
ThreadUtils.postOnUiThread(new Runnable() {
@Override
public void run() {
getContext().getContentResolver().notifyChange(uri, null);
}
});
return;
}
}
getContext().getContentResolver().notifyChange(uri, null);
}
@SuppressLint("NewApi")
private void notifyChange(final Uri uri) {
// If the calling user is different than current one, we need to post a
// task to notify change, otherwise, a system level hidden permission
// INTERACT_ACROSS_USERS_FULL is needed.
// The related APIs were added in API 17, it should be safe to fallback to
// normal way for notifying change, because caller can't be other users in
// devices whose API level is less than API 17.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
UserHandle callingUserHandle = Binder.getCallingUserHandle();
if (callingUserHandle != null
&& !callingUserHandle.equals(android.os.Process.myUserHandle())) {
ThreadUtils.postOnUiThread(new Runnable() {
@Override
public void run() {
getContext().getContentResolver().notifyChange(uri, null);
}
});
return;
}
}
getContext().getContentResolver().notifyChange(uri, null);
}
public UserHandle getCallingUserHandle() {
return Binder.getCallingUserHandle();
}