Example usage for android.os UserManager DISALLOW_OUTGOING_BEAM

List of usage examples for android.os UserManager DISALLOW_OUTGOING_BEAM

Introduction

In this page you can find the example usage for android.os UserManager DISALLOW_OUTGOING_BEAM.

Prototype

String DISALLOW_OUTGOING_BEAM

To view the source code for android.os UserManager DISALLOW_OUTGOING_BEAM.

Click Source Link

Document

Specifies if the user is not allowed to use NFC to beam out data from apps.

Usage

From source file:com.android.cts.verifier.managedprovisioning.NfcTestActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.byod_nfc_test_activity);

    mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName());
    mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
    mUserMangaer = (UserManager) getSystemService(Context.USER_SERVICE);
    mDisallowByPolicy = getIntent().getBooleanExtra(EXTRA_DISALLOW_BY_POLICY, false);
    if (mDisallowByPolicy) {
        mDevicePolicyManager.addUserRestriction(mAdminReceiverComponent, UserManager.DISALLOW_OUTGOING_BEAM);
    }//  w w  w .j a v  a2 s .c  o m

    final Uri uri = createUriForImage(SAMPLE_IMAGE_FILENAME, SAMPLE_IMAGE_CONTENT);
    Uri[] uris = new Uri[] { uri };

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    mNfcAdapter.setBeamPushUris(uris, this);

    findViewById(R.id.manual_beam_button).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mNfcAdapter.invokeBeam(NfcTestActivity.this);
        }
    });
    findViewById(R.id.intent_share_button).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
            shareIntent.setType("image/jpg");
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            // Specify the package name of NfcBeamActivity so that the tester don't need to
            // select the activity manually.
            shareIntent.setClassName(NFC_BEAM_PACKAGE, NFC_BEAM_ACTIVITY);
            try {
                startActivity(shareIntent);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(NfcTestActivity.this, R.string.provisioning_byod_cannot_resolve_beam_activity,
                        Toast.LENGTH_SHORT).show();
                Log.e(TAG, "Nfc beam activity not found", e);
            }
        }
    });
}

From source file:com.android.cts.verifier.managedprovisioning.NfcTestActivity.java

@Override
public void finish() {
    if (mUserMangaer.hasUserRestriction(UserManager.DISALLOW_OUTGOING_BEAM)) {
        mDevicePolicyManager.clearUserRestriction(mAdminReceiverComponent, UserManager.DISALLOW_OUTGOING_BEAM);
    }/* ww  w. j av a  2 s  . c  o m*/
    super.finish();
}