Search in sources :

Example 16 with NfcAdapter

use of android.nfc.NfcAdapter 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)

Example 17 with NfcAdapter

use of android.nfc.NfcAdapter in project AndroidChromium by JackyAndroid.

the class Preferences method onCreate.

@SuppressFBWarnings("DM_EXIT")
@SuppressLint("InlinedApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    ensureActivityNotExported();
    // recreate a fragment, and a fragment might depend on the native library.
    try {
        ChromeBrowserInitializer.getInstance(this).handleSynchronousStartup();
    } catch (ProcessInitException e) {
        Log.e(TAG, "Failed to start browser process.", e);
        // This can only ever happen, if at all, when the activity is started from an Android
        // notification (or in tests). As such we don't want to show an error messsage to the
        // user. The application is completely broken at this point, so close it down
        // completely (not just the activity).
        System.exit(-1);
        return;
    }
    super.onCreate(savedInstanceState);
    mIsNewlyCreated = savedInstanceState == null;
    String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
    Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    // recreated and super.onCreate() has already recreated the fragment.
    if (savedInstanceState == null) {
        if (initialFragment == null)
            initialFragment = MainPreferences.class.getName();
        Fragment fragment = Fragment.instantiate(this, initialFragment, initialArguments);
        getFragmentManager().beginTransaction().replace(android.R.id.content, fragment).commit();
    }
    if (ApiCompatibilityUtils.checkPermission(this, Manifest.permission.NFC, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED) {
        // Disable Android Beam on JB and later devices.
        // In ICS it does nothing - i.e. we will send a Play Store link if NFC is used.
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter != null)
            nfcAdapter.setNdefPushMessage(null, this);
    }
    Resources res = getResources();
    ApiCompatibilityUtils.setTaskDescription(this, res.getString(R.string.app_name), BitmapFactory.decodeResource(res, R.mipmap.app_icon), ApiCompatibilityUtils.getColor(res, R.color.default_primary_color));
}
Also used : Bundle(android.os.Bundle) NfcAdapter(android.nfc.NfcAdapter) ProcessInitException(org.chromium.base.library_loader.ProcessInitException) Resources(android.content.res.Resources) Fragment(android.app.Fragment) PreferenceFragment(android.preference.PreferenceFragment) SuppressFBWarnings(org.chromium.base.annotations.SuppressFBWarnings) SuppressLint(android.annotation.SuppressLint)

Example 18 with NfcAdapter

use of android.nfc.NfcAdapter in project AndroidChromium by JackyAndroid.

the class BeamController method registerForBeam.

/**
     * If the device has NFC, construct a BeamCallback and pass it to Android.
     *
     * @param activity Activity that is sending out beam messages.
     * @param provider Provider that returns the URL that should be shared.
     */
public static void registerForBeam(final Activity activity, final BeamProvider provider) {
    final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
    if (nfcAdapter == null)
        return;
    if (ApiCompatibilityUtils.checkPermission(activity, Manifest.permission.NFC, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_DENIED) {
        return;
    }
    try {
        final BeamCallback beamCallback = new BeamCallback(activity, provider);
        nfcAdapter.setNdefPushMessageCallback(beamCallback, activity);
        nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity);
    } catch (IllegalStateException e) {
        Log.w("BeamController", "NFC registration failure. Can't retry, giving up.");
    }
}
Also used : NfcAdapter(android.nfc.NfcAdapter)

Example 19 with NfcAdapter

use of android.nfc.NfcAdapter in project platform_frameworks_base by android.

the class NfcFCardEmulation method recoverService.

void recoverService() {
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext);
    sService = adapter.getNfcFCardEmulationService();
}
Also used : NfcAdapter(android.nfc.NfcAdapter)

Example 20 with NfcAdapter

use of android.nfc.NfcAdapter in project android_frameworks_base by DirtyUnicorns.

the class NfcFCardEmulation method recoverService.

void recoverService() {
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mContext);
    sService = adapter.getNfcFCardEmulationService();
}
Also used : NfcAdapter(android.nfc.NfcAdapter)

Aggregations

NfcAdapter (android.nfc.NfcAdapter)22 Activity (android.app.Activity)4 NdefMessage (android.nfc.NdefMessage)3 NdefRecord (android.nfc.NdefRecord)3 NfcEvent (android.nfc.NfcEvent)2 SuppressLint (android.annotation.SuppressLint)1 Fragment (android.app.Fragment)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 ResolveInfo (android.content.pm.ResolveInfo)1 Resources (android.content.res.Resources)1 WifiConfiguration (android.net.wifi.WifiConfiguration)1 Tag (android.nfc.Tag)1 Bundle (android.os.Bundle)1 UserManager (android.os.UserManager)1 PreferenceFragment (android.preference.PreferenceFragment)1 Preference (android.support.v7.preference.Preference)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1