Search in sources :

Example 1 with NfcEvent

use of android.nfc.NfcEvent in project android_packages_apps_Gallery2 by LineageOS.

the class PhotoPage method setupNfcBeamPush.

@TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
private void setupNfcBeamPush() {
    if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS)
        return;
    try {
        NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mActivity);
        if (adapter != null) {
            adapter.setBeamPushUris(null, mActivity);
            adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {

                @Override
                public Uri[] createBeamUris(NfcEvent event) {
                    return mNfcPushUris;
                }
            }, mActivity);
        }
    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : NfcEvent(android.nfc.NfcEvent) NfcAdapter(android.nfc.NfcAdapter) CreateBeamUrisCallback(android.nfc.NfcAdapter.CreateBeamUrisCallback) ActivityNotFoundException(android.content.ActivityNotFoundException) TargetApi(android.annotation.TargetApi)

Example 2 with NfcEvent

use of android.nfc.NfcEvent in project android_packages_apps_Snap by LineageOS.

the class CameraActivity method setupNfcBeamPush.

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void setupNfcBeamPush() {
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(CameraActivity.this);
    if (adapter == null) {
        return;
    }
    if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS) {
        // Disable beaming
        adapter.setNdefPushMessage(null, CameraActivity.this);
        return;
    }
    adapter.setBeamPushUris(null, CameraActivity.this);
    adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {

        @Override
        public Uri[] createBeamUris(NfcEvent event) {
            return mNfcPushUris;
        }
    }, CameraActivity.this);
}
Also used : NfcEvent(android.nfc.NfcEvent) NfcAdapter(android.nfc.NfcAdapter) CreateBeamUrisCallback(android.nfc.NfcAdapter.CreateBeamUrisCallback) TargetApi(android.annotation.TargetApi)

Example 3 with NfcEvent

use of android.nfc.NfcEvent in project i2p.i2p-bote by i2p.

the class ViewContactActivity method onCreate.

@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState == null) {
        String destination = null;
        Bundle args = getIntent().getExtras();
        if (args != null)
            destination = args.getString(ViewContactFragment.ADDRESS);
        if (destination == null) {
            setResult(RESULT_CANCELED);
            finish();
            return;
        }
        ViewContactFragment f = ViewContactFragment.newInstance(destination);
        getSupportFragmentManager().beginTransaction().add(android.R.id.content, f).commit();
    }
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        mNfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {

            @Override
            public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
                return getNdefMessage();
            }
        }, this);
    }
}
Also used : NfcEvent(android.nfc.NfcEvent) Bundle(android.os.Bundle) NdefMessage(android.nfc.NdefMessage) NfcAdapter(android.nfc.NfcAdapter) SuppressLint(android.annotation.SuppressLint)

Example 4 with NfcEvent

use of android.nfc.NfcEvent in project weiciyuan by qii.

the class MainTimeLineParentActivity method initNFC.

private void initNFC() {
    NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {
        return;
    }
    mNfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {

        @Override
        public NdefMessage createNdefMessage(NfcEvent event) {
            String text = (GlobalContext.getInstance().getCurrentAccountName());
            NdefMessage msg = new NdefMessage(new NdefRecord[] { createMimeRecord("application/org.qii.weiciyuan.beam", text.getBytes()), NdefRecord.createApplicationRecord(getPackageName()) });
            return msg;
        }
    }, this);
}
Also used : NdefRecord(android.nfc.NdefRecord) NfcEvent(android.nfc.NfcEvent) NdefMessage(android.nfc.NdefMessage) NfcAdapter(android.nfc.NfcAdapter)

Example 5 with NfcEvent

use of android.nfc.NfcEvent in project weiciyuan by qii.

the class AbstractAppActivity method initNFC.

private void initNFC() {
    NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {
        return;
    }
    mNfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {

        @Override
        public NdefMessage createNdefMessage(NfcEvent event) {
            String text = (GlobalContext.getInstance().getCurrentAccountName());
            NdefMessage msg = new NdefMessage(new NdefRecord[] { createMimeRecord("application/org.qii.weiciyuan.beam", text.getBytes()), NdefRecord.createApplicationRecord(getPackageName()) });
            return msg;
        }
    }, this);
}
Also used : NdefRecord(android.nfc.NdefRecord) NfcEvent(android.nfc.NfcEvent) NdefMessage(android.nfc.NdefMessage) NfcAdapter(android.nfc.NfcAdapter)

Aggregations

NfcAdapter (android.nfc.NfcAdapter)6 NfcEvent (android.nfc.NfcEvent)6 NdefMessage (android.nfc.NdefMessage)4 SuppressLint (android.annotation.SuppressLint)2 TargetApi (android.annotation.TargetApi)2 NdefRecord (android.nfc.NdefRecord)2 CreateBeamUrisCallback (android.nfc.NfcAdapter.CreateBeamUrisCallback)2 Bundle (android.os.Bundle)2 ActivityNotFoundException (android.content.ActivityNotFoundException)1