コード例 #1
0
  @Override
  public FREObject call(FREContext arg0, FREObject[] arg1) {

    Activity a = arg0.getActivity();
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(a);

    try {
      if (adapter == null) {
        return FREObject.newObject(false);
      }
    } catch (Exception e) {
    }
    NfcNdefManager.getInstance().adapter = NfcAdapter.getDefaultAdapter(a);
    NfcNdefManager.getInstance().pIntent =
        PendingIntent.getActivity(
            a, 0, new Intent(a, a.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    IntentFilter ndefFilter = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
      ndefFilter.addDataType("text/plain");
    } catch (MalformedMimeTypeException mmte) {
    }
    NfcNdefManager.getInstance().ndefFilters = new IntentFilter[] {ndefFilter};

    IntentFilter tagFilter = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    NfcNdefManager.getInstance().tagFilters = new IntentFilter[] {tagFilter};

    try {
      return FREObject.newObject(true);
    } catch (Exception e) {
    }
    return null;
  }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    pendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
      ndef.addDataType("text/plain");
    } catch (MalformedMimeTypeException e) {
      throw new RuntimeException("失敗", e);
    }
    intentFiltersArray = new IntentFilter[] {ndef};

    techListsArray =
        new String[][] {
          new String[] {NfcA.class.getName(), Ndef.class.getName()},
          new String[] {NfcF.class.getName()}
        };
  }
コード例 #3
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    beamFragment =
        (BeamFragment) getSupportFragmentManager().findFragmentById(android.R.id.content);

    if (beamFragment == null) {
      beamFragment = new BeamFragment();

      getSupportFragmentManager()
          .beginTransaction()
          .add(android.R.id.content, beamFragment)
          .commit();
    }

    adapter = NfcAdapter.getDefaultAdapter(this);

    findViewById(android.R.id.content)
        .post(
            new Runnable() {
              public void run() {
                handleIntent(getIntent());
              }
            });
  }
コード例 #4
0
 public void onCreate(Bundle savedInstanceState) {
   try {
     super.onCreate(savedInstanceState);
     nfcAdapter = NfcAdapter.getDefaultAdapter(this);
     if (nfcAdapter != null) {
       pendingIntent =
           PendingIntent.getActivity(
               this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
       ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
       ndef.addDataType("*/*");
       filters =
           new IntentFilter[] {
             ndef,
           };
       techLists = new String[][] {new String[] {MifareClassic.class.getName()}};
     } else {
       throw new FsgException(
           new NullPointerException(
               "'Der NfcAdapter ist ein \"null\"-Objekt. Grund: Keine NFC-Unterstützung auf dem Gerät"),
           this.getClass().toString(),
           FsgException.NOT_NFC_SUPPORT);
     }
   } catch (MalformedMimeTypeException e) {
     throw new RuntimeException("fail", e);
   } catch (FsgException e1) {
     Intent mIntent = new Intent(this, ErrorActivity.class);
     mIntent.putExtra("Exception", e1);
     startActivity(mIntent);
     finish();
   }
 }
コード例 #5
0
  public static boolean powerNfc(boolean isOn, Context context) {
    boolean success = false;
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);

    if (nfcAdapter != null) {
      Class<?> NfcManagerClass;
      Method setNfcEnabled;

      try {
        NfcManagerClass = Class.forName(nfcAdapter.getClass().getName());
        setNfcEnabled = NfcManagerClass.getDeclaredMethod(isOn ? "enable" : "disable");
        setNfcEnabled.setAccessible(true);
        success = (Boolean) setNfcEnabled.invoke(nfcAdapter);
      } catch (ClassNotFoundException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (NoSuchMethodException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (IllegalArgumentException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (IllegalAccessException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      } catch (InvocationTargetException e) {
        Log.e(TAG, Log.getStackTraceString(e));
      }
    }

    return success;
  }
コード例 #6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    consumpties.add(new Consumptie(1, "Fanta"));
    consumpties.add(new Consumptie(1, "Cola"));
    consumpties.add(new Consumptie(1, "Sprite"));

    consumpties.add(new Consumptie(2, "Grolsch Bier"));

    consumpties.add(new Consumptie(3, "Witte Wijn"));
    consumpties.add(new Consumptie(3, "Rode Wijn"));
    consumpties.add(new Consumptie(3, "Speciaal Bier"));

    nfcAdapter = NfcAdapter.getDefaultAdapter(this);

    if (nfcAdapter != null && nfcAdapter.isEnabled()) {

    } else {
      finish();
    }
  }
コード例 #7
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getResources().getBoolean(R.bool.portrait_only)) {
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    setContentView(R.layout.activity_review_poll);
    setupActionBar();

    if (getResources().getBoolean(R.bool.display_bottom_bar) == false) {
      findViewById(R.id.layout_bottom_bar).setVisibility(View.GONE);
    }

    AndroidApplication.getInstance().setCurrentActivity(this);
    AndroidApplication.getInstance().getNetworkInterface().lockGroup();

    btnStartPollPeriod = (Button) findViewById(R.id.button_start_poll_period);
    btnStartPollPeriod.setOnClickListener(this);

    if (savedInstanceState != null) {
      poll = (Poll) savedInstanceState.getSerializable("poll");
      sender = savedInstanceState.getString("sender");
    }

    Poll intentPoll = (Poll) getIntent().getSerializableExtra("poll");
    if (intentPoll != null) {
      poll = intentPoll;
      sender = getIntent().getStringExtra("sender");
    }

    FragmentManager fm = getFragmentManager();
    fragment = new PollReviewFragment();
    Bundle bundle = new Bundle();
    bundle.putSerializable("poll", poll);
    bundle.putString("sender", sender);
    fragment.setArguments(bundle);

    fm.beginTransaction().replace(R.id.fragment_container, fragment, "review").commit();

    // Is NFC available on this device?
    nfcAvailable = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);

    if (nfcAvailable) {

      nfcAdapter = NfcAdapter.getDefaultAdapter(this);

      if (nfcAdapter.isEnabled()) {

        // Setting up a pending intent that is invoked when an NFC tag
        // is tapped on the back
        pendingIntent =
            PendingIntent.getActivity(
                this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
      } else {
        nfcAvailable = false;
      }
    }
  }
コード例 #8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null)
                .show();
          }
        });

    nfcAdapter = NfcAdapter.getDefaultAdapter(this); // argument is "Context"
    if (nfcAdapter == null) {
      Toast.makeText(this, "Not a NFC device", Toast.LENGTH_SHORT).show();
      return;
    }

    // TODO go AsyncTask
    onNewIntent(getIntent());
  }
コード例 #9
0
ファイル: NFCard.java プロジェクト: wangzhen90/MyApp
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.nfcard);

    final Resources res = getResources();
    this.res = res;

    final View decor = getWindow().getDecorView();
    final TextView board = (TextView) decor.findViewById(R.id.board);
    this.board = board;

    decor.findViewById(R.id.btnCopy).setOnClickListener(this);
    decor.findViewById(R.id.btnNfc).setOnClickListener(this);
    decor.findViewById(R.id.btnExit).setOnClickListener(this);

    board.setMovementMethod(LinkMovementMethod.getInstance());
    board.setFocusable(false);
    board.setClickable(false);
    board.setLongClickable(false);

    nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    pendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    onNewIntent(getIntent());
  }
コード例 #10
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    deviceNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (deviceNfcAdapter != null) {
      // Refer back to createNdefMessage to send
      deviceNfcAdapter.setNdefPushMessageCallback(this, this);

      // This will be called if message sent successfully
      deviceNfcAdapter.setOnNdefPushCompleteCallback(this, this);
    } else {
      Toast.makeText(this, "NFC not available on your device.", Toast.LENGTH_LONG).show();
    }

    addMessageInput = (EditText) findViewById(R.id.txtBoxAddMessage);
    messagesToSend = (TextView) findViewById(R.id.txtMessageToSend);
    receivedMessageOutput = (TextView) findViewById(R.id.txtMessagesReceived);
    Button addMessage = (Button) findViewById(R.id.buttonAddMessage);

    updateTextViews();

    if (getIntent().getAction().equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) {
      handleNfcIntent(getIntent());
    }
  }
コード例 #11
0
 public void testNfcFeatures() {
   if (NfcAdapter.getDefaultAdapter(mContext) != null) {
     assertAvailable(PackageManager.FEATURE_NFC);
   } else {
     assertNotAvailable(PackageManager.FEATURE_NFC);
   }
 }
コード例 #12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
    // getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
    setContentView(R.layout.activity_main);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    if (mNfcAdapter == null) {
      // Stop here, we definitely need NFC
      Toast.makeText(this, "This device doesn't support NFC.", Toast.LENGTH_LONG).show();
      finish();
      return;
    }

    if (!mNfcAdapter.isEnabled()) {
      Toast.makeText(this, "NFC is disabled.", Toast.LENGTH_LONG).show();
    }

    handleIntent(getIntent());
  }
コード例 #13
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tag_info_viewer);
    mCard = ((MyApplication) getApplication()).getCurrentCard();

    showStateDialog();

    initControl();

    mPendingIntent =
        PendingIntent.getActivity(
            this,
            0,
            new Intent(this, getClass())
                .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
                .setComponent(getComponentName()),
            0);

    IntentFilter nfcTech = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);

    mFilters =
        new IntentFilter[] {
          nfcTech,
        };

    mTechLists =
        new String[][] {new String[] {NfcA.class.getName()}, new String[] {IsoDep.class.getName()}};

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
  }
コード例 #14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // creating pending intent
    pendingIntent =
        PendingIntent.getActivity(
            this,
            0,
            new Intent(getApplicationContext(), this.getClass())
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY),
            0);

    i[0] = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    // creating tech list for tag
    techListsArray =
        new String[][] {
          new String[] {
            NfcV.class.getName(),
            NfcA.class.getName(),
            NfcB.class.getName(),
            NfcF.class.getName(),
            Ndef.class.getName(),
            NdefFormatable.class.getName(),
            MifareClassic.class.getName(),
            MifareUltralight.class.getName()
          }
        };

    // creating object of nfc adapter of mobile device
    NFCAdapter = NfcAdapter.getDefaultAdapter(this);

    // if app is opened after pop up....
    ScanTag(getIntent());
  }
コード例 #15
0
ファイル: Scan.java プロジェクト: kornfeldc/OG125
  private void setUpForegroundDispatchSystem() {
    this.nfcAdapter = NfcAdapter.getDefaultAdapter(this);

    this.pendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
      ndef.addDataType("*/*"); /* Handles all MIME based dispatches.
                                           You should specify only the ones that you need. */
      ndef.addDataScheme("http");
    } catch (IntentFilter.MalformedMimeTypeException e) {
      throw new RuntimeException("fail", e);
    }
    IntentFilter td = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    this.intentFiltersArray = new IntentFilter[] {ndef, td};
    this.techListsArray =
        new String[][] {
          new String[] {
            MifareUltralight.class.getName(), Ndef.class.getName(), NfcA.class.getName()
          },
          new String[] {MifareClassic.class.getName(), Ndef.class.getName(), NfcA.class.getName()}
        };
  }
コード例 #16
0
ファイル: MainActivity.java プロジェクト: aml2610/autolec
  @Override
  public void onCreate(Bundle savedInstanceState) {

    // TODO -> EXIT
    // Just initialisation of the activity
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    lecnoteButton = (Button) findViewById(R.id.lecnoteButton);
    lecnoteButton.setEnabled(false);
    surveyButton = (Button) findViewById(R.id.surveyButton);
    surveyButton.setEnabled(false);
    textView = (TextView) findViewById(R.id.welcomeMessage);

    // Restore stored preferences
    settings = getPreferences(Context.MODE_PRIVATE);
    editor = settings.edit();
    studentID = settings.getInt("studentID", 0);
    adjustWiFi = settings.getBoolean("adjustWiFi", true);
    adjustSound = settings.getBoolean("adjustSound", true);
    adjustBrightness = settings.getBoolean("adjustBrightness", true);

    // Check for available NFC Adapter
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {
      Toast.makeText(this, "NFC is not available", Toast.LENGTH_LONG).show();
      finish();
      return;
    }
  }
コード例 #17
0
 @TargetApi(14)
 private void initNFC() {
   NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
   if (nfc != null) {
     nfc.setNdefPushMessageCallback(new NfcCallback(server), this);
   }
 }
コード例 #18
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    try {
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      super.onCreate(savedInstanceState);
      setContentView(R.layout.nueva_etiqueta);

      context = this;

      b = getIntent().getExtras();
      message = b.getString("grabarTAG");

      // Los elementos que vamos a usar en el layout
      Button btnWrite = (Button) findViewById(R.id.btnguardar);
      // final TextView message = (TextView)findViewById(R.id.);
      // setOnCLickListener hará la acción que necesitamos
      btnWrite.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {

              try {
                // Si no existe tag al que escribir, mostramos un mensaje de que no existe.
                if (myTag == null) {
                  Toast.makeText(
                          context, context.getString(R.string.error_notag), Toast.LENGTH_LONG)
                      .show();
                } else {
                  // Llamamos al método write que definimos más adelante donde le pasamos por
                  // parámetro el tag que hemos detectado y el mensaje a escribir.
                  write(message, myTag);
                  Toast.makeText(context, context.getString(R.string.ok_write), Toast.LENGTH_LONG)
                      .show();
                  lanzarPrincipal(v);
                }
              } catch (IOException e) {
                Toast.makeText(context, context.getString(R.string.error_write), Toast.LENGTH_LONG)
                    .show();
                e.printStackTrace();
              } catch (FormatException e) {
                Toast.makeText(context, context.getString(R.string.error_write), Toast.LENGTH_LONG)
                    .show();
                e.printStackTrace();
              }
            }
          });

      adapter = NfcAdapter.getDefaultAdapter(this);
      pendingIntent =
          PendingIntent.getActivity(
              this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
      IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
      tagDetected.addCategory(Intent.CATEGORY_DEFAULT);
      writeTagFilters = new IntentFilter[] {tagDetected};
    } catch (Exception e) {
      Log.d("NUEBA ETIQUETA ONCREATE", "Excepción: " + e.getMessage());
    }
  } // onCreate
コード例 #19
0
 @TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1)
 void checkNFC() {
   mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
   Log.d(TAG, "NFC init");
   if (mNfcAdapter != null) {
     Log.d(TAG, "NFC supported");
   }
 }
コード例 #20
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // set the main.xml layout of 3 editable textfields and an update
    // button:
    setContentView(R.layout.nfc_beam);
    findViewById(R.id.write_tag).setOnClickListener(mTagWriter);
    mName = ((EditText) findViewById(R.id.computer_name));
    mRAM = ((EditText) findViewById(R.id.computer_ram));
    mProcessor = ((EditText) findViewById(R.id.computer_processor));

    // get an instance of the context's cached NfcAdapter
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);

    // if null is returned this demo cannot run. Use this check if the
    // "required" parameter of <uses-feature> in the manifest is not set
    if (mNfcAdapter == null) {
      Toast.makeText(this, "Your device does not support NFC. Cannot run demo.", Toast.LENGTH_LONG)
          .show();
      finish();
      return;
    }

    // check if NFC is enabled
    checkNfcEnabled();

    // Handle foreground NFC scanning in this activity by creating a
    // PendingIntent with FLAG_ACTIVITY_SINGLE_TOP flag so each new scan
    // is not added to the Back Stack
    mNfcPendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Create intent filter to handle NDEF NFC tags detected from inside our
    // application when in "read mode":
    IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
      ndefDetected.addDataType("application/root.gast.playground.nfc");
    } catch (MalformedMimeTypeException e) {
      throw new RuntimeException("Could not add MIME type.", e);
    }

    // Create intent filter to detect any NFC tag when attempting to write
    // to a tag in "write mode"
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);

    // create IntentFilter arrays:
    mWriteTagFilters = new IntentFilter[] {tagDetected};
    mReadTagFilters = new IntentFilter[] {ndefDetected, tagDetected};

    // register the callback
    // usage: setNdefPushMessageCallback( callback, activity,
    // optionalExtraActivities)
    mNfcAdapter.setNdefPushMessageCallback(this, this);
  }
コード例 #21
0
 @Override
 protected void onPause() {
   super.onPause();
   // disabling foreground dispatch:
   NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
   if (nfcAdapter != null) {
     nfcAdapter.disableForegroundDispatch(this);
   }
 }
コード例 #22
0
ファイル: NFMain.java プロジェクト: jmnwong/NFConnect
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_nfmain);

    mInfoText = (TextView) findViewById(R.id.textView);
    // Check for available NFC Adapter
    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {
      mInfoText = (TextView) findViewById(R.id.textView);
      mInfoText.setText("NFC is not available on this device.");
    } else {
      // Register callback to set NDEF message
      mNfcAdapter.setNdefPushMessageCallback(this, this);
      // Register callback to listen for message-sent success
      mNfcAdapter.setOnNdefPushCompleteCallback(this, this);
    }

    // start Facebook Login
    Session.openActiveSession(
        this,
        true,
        new Session.StatusCallback() {

          // callback when session changes state
          @Override
          public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {

              // make request to the /me API
              Request.executeMeRequestAsync(
                  session,
                  new Request.GraphUserCallback() {

                    // callback after Graph API response with user object
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                      if (user != null) {
                        Toast.makeText(
                                getApplicationContext(),
                                "Welcome " + user.getName() + " : " + user.getId() + "!",
                                Toast.LENGTH_LONG)
                            .show();
                        userId = user.getId();
                      }
                    }
                  });
            }
          }
        });
  }
コード例 #23
0
  /** NFC書き込み可能状態にする */
  private void enableTagWriteMode() {

    // このアプリ以外がNFCに反応しないようにする
    mWriteTagFilters = new IntentFilter[] {new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED)};
    Intent intent = new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent nfcIntent = PendingIntent.getActivity(this, 0, intent, 0);

    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    nfcAdapter.enableForegroundDispatch(this, nfcIntent, mWriteTagFilters, null);
  }
コード例 #24
0
 public void checkNfcAvailibility() {
   nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
   if (nfcAdapter == null) {
     callbackContext.error(STATUS_NO_NFC);
   } else if (!nfcAdapter.isEnabled()) {
     callbackContext.error(STATUS_NFC_DISABLED);
   } else {
     callbackContext.success(STATUS_NFC_OK);
   }
 }
コード例 #25
0
  public static boolean checkNfcPowerStatus(Context context) {
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
    boolean enabled = false;

    if (nfcAdapter != null) {
      enabled = nfcAdapter.isEnabled();
    }

    return enabled;
  }
コード例 #26
0
 /**
  * Constructor of this class
  *
  * @param pActivity activity context
  */
 public NFCUtils(final Activity pActivity) {
   mActivity = pActivity;
   mNfcAdapter = NfcAdapter.getDefaultAdapter(mActivity);
   mPendingIntent =
       PendingIntent.getActivity(
           mActivity,
           0,
           new Intent(mActivity, mActivity.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
           0);
 }
コード例 #27
0
 /**
  * Check if the NFCAdapter is enable
  *
  * @return true if the NFCAdapter is available enable
  */
 public static boolean isNfcEnable(final Context pContext) {
   boolean ret = true;
   try {
     NfcAdapter adpater = NfcAdapter.getDefaultAdapter(pContext);
     ret = adpater != null && adpater.isEnabled();
   } catch (UnsupportedOperationException e) {
     ret = false;
   }
   return ret;
 }
コード例 #28
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.reader);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar); // titlebar为自己标题栏的布局

    this.leftButton = (Button) this.findViewById(R.id.leftButton);
    this.rightButton = (Button) this.findViewById(R.id.rightButton);
    this.titleText = (TextView) this.findViewById(R.id.titleText);

    this.leftButton.setOnClickListener(this);
    this.rightButton.setOnClickListener(this);
    this.rightButton.setVisibility(View.GONE);
    this.titleText.setText("Read Card");

    KeyInfoDao dao = new KeyInfoDao(this);
    List<Key> keyList = dao.getAllKeyInfo();
    defaultKeys = new String[keyList.size()];
    for (int i = 0; i < keyList.size(); i++) {
      defaultKeys[i] = keyList.get(i).getKeyValue();
    }

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity.
    // The NFC stack
    // will fill in the intent with the details of the discovered tag before
    // delivering to
    // this activity.
    mPendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Setup an intent filter for all MIME based dispatches
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);

    try {
      ndef.addDataType("*/*");
    } catch (MalformedMimeTypeException e) {
      throw new RuntimeException("fail", e);
    }

    mFilters =
        new IntentFilter[] {
          ndef,
        };

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] {new String[] {MifareClassic.class.getName()}};

    Intent intent = getIntent();
    resolveIntent(intent);
  }
コード例 #29
0
ファイル: NfcActivity.java プロジェクト: vtloc/glass-earth
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null || !mNfcAdapter.isEnabled()) {
      Toast.makeText(this, "NFC is turn off or disabled", Toast.LENGTH_LONG).show();
    }

    handleIntend(getIntent());
  }
コード例 #30
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pass_bolt_login);

    resolveIntent(getIntent());

    // Set up the login form.
    mUserNameView = (AutoCompleteTextView) findViewById(R.id.username);
    // populateAutoComplete();

    mPasswordView = (EditText) findViewById(R.id.password);

    emailLoginFormLayout = (LinearLayout) findViewById(R.id.email_login_form);

    mCardIDView = (EditText) findViewById(R.id.card_id);
    mCardIDView.setKeyListener(null);

    Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
    mEmailSignInButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            attemptLogin(view);
          }
        });

    mLoginFormView = findViewById(R.id.login_form);
    mProgressView = findViewById(R.id.login_progress);

    mDialog = new AlertDialog.Builder(this).setNeutralButton("Ok", null).create();

    mAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mAdapter == null) {
      showMessage(R.string.error, R.string.no_nfc);
      finish();
      return;
    }

    if (!mAdapter.isEnabled()) {
      showMessage(R.string.error, R.string.disabled_nfc);
      finish();
      return;
    }

    mPendingIntent =
        PendingIntent.getActivity(
            this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    mNdefPushMessage =
        new NdefMessage(
            new NdefRecord[] {
              createNewTextRecord("Message from NFC Reader", Locale.ENGLISH, true)
            });
  }