Example usage for android.accounts AccountManager KEY_CALLER_UID

List of usage examples for android.accounts AccountManager KEY_CALLER_UID

Introduction

In this page you can find the example usage for android.accounts AccountManager KEY_CALLER_UID.

Prototype

String KEY_CALLER_UID

To view the source code for android.accounts AccountManager KEY_CALLER_UID.

Click Source Link

Document

The UID of caller app.

Usage

From source file:uk.ac.bournemouth.darwin.auth.AuthTokenPermissionActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mBinding = DataBindingUtil.setContentView(this, R.layout.get_permission);
    mBinding.setAccount(getIntent().<Account>getParcelableExtra(DarwinAuthenticator.KEY_ACCOUNT));
    mCallerUid = getIntent().getIntExtra(AccountManager.KEY_CALLER_UID, -1);
    final PackageManager pm = getPackageManager();
    String callerPackage = pm.getPackagesForUid(mCallerUid)[0];
    String packageName;//from w  ww.  ja  v  a  2 s .c o  m
    try {
        final PackageInfo packageInfo = pm.getPackageInfo(callerPackage, 0);
        int labelRes = packageInfo.applicationInfo.labelRes;
        packageName = pm.getResourcesForApplication(packageInfo.applicationInfo).getString(labelRes);
    } catch (NameNotFoundException e) {
        Log.w(TAG, "onCreate: ", e);
        packageName = callerPackage;
    }

    mBinding.setCallerName(packageName);
    mBinding.cancelbutton.setOnClickListener(this);
    mBinding.okbutton.setOnClickListener(this);
}