Ejemplo n.º 1
0
 // Check whether NFC is enabled on the device on not
 public static boolean isNFCEnabled(Context appContext) {
   NfcManager manager = (NfcManager) appContext.getSystemService(Context.NFC_SERVICE);
   NfcAdapter adapter = manager.getDefaultAdapter();
   if (adapter != null && adapter.isEnabled()) {
     Log.i(TAG, "NFC Supproted and Enabled");
     return true;
   } else if (adapter != null && !adapter.isEnabled()) {
     Log.i(TAG, "NFC Supproted and Disabled");
     return false;
   }
   return false;
 }
Ejemplo n.º 2
0
 @Override
 protected void onNewIntent(Intent intent) {
   super.onNewIntent(intent);
   if (nfcAdapter != null && nfcAdapter.isEnabled()) {
     nfcAsyncTask = new NfcAsyncTask(intent);
   }
 }
Ejemplo n.º 3
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();
    }
  }
Ejemplo n.º 4
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;
      }
    }
  }
Ejemplo n.º 5
0
  @Override
  protected void onResume() {
    AndroidApplication.getInstance().setCurrentActivity(this);
    LocalBroadcastManager.getInstance(NetworkConfigActivity.this)
        .registerReceiver(
            serviceStartedListener,
            new IntentFilter(BroadcastIntentTypes.networkConnectionSuccessful));

    active = true;
    rescanWifiTask =
        new AsyncTask<Object, Object, Object>() {

          @Override
          protected Object doInBackground(Object... arg0) {

            while (active) {
              SystemClock.sleep(5000);
              wifi.startScan();
            }
            return null;
          }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

    if (nfcAdapter != null && nfcAdapter.isEnabled()) {
      nfcAvailable = true;
    }

    // make sure that this activity is the first one which can handle the
    // NFC tags
    if (nfcAvailable) {
      nfcAdapter.enableForegroundDispatch(this, pendingIntent, Utility.getNFCIntentFilters(), null);
    }

    super.onResume();
  }
Ejemplo n.º 6
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());
  }
 private void enableNFCAdapterSenses() {
   if (mAdapter != null) {
     if (!mAdapter.isEnabled()) {
       showWirelessSettingsDialog();
     }
     mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
     mAdapter.enableForegroundNdefPush(this, mNdefPushMessage);
   }
 }
Ejemplo n.º 8
0
  public void setIcons() {

    if (mNfcAdapter == null) {
      item.setIcon(R.drawable.nfc_not_found);
    } else if (!mNfcAdapter.isEnabled()) {
      item.setIcon(R.drawable.nfc_off);
    } else {
      item.setIcon(R.drawable.nfc_on);
    }
  }
  public static boolean checkNfcPowerStatus(Context context) {
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
    boolean enabled = false;

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

    return enabled;
  }
 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);
   }
 }
Ejemplo n.º 11
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;
 }
 @TargetApi(Build.VERSION_CODES.GINGERBREAD)
 void initNfcBox() {
   if (mNfcAdapter.isEnabled()) {
     useNFCBox.setChecked(true);
     useNFC = true;
   } else {
     useNFCBox.setChecked(false);
     useNFC = false;
   }
 }
Ejemplo n.º 13
0
 @Override
 protected void onResume() {
   super.onResume();
   if (mAdapter != null) {
     if (!mAdapter.isEnabled()) {
       showWirelessSettingsDialog();
     }
     mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
   }
 };
Ejemplo n.º 14
0
 public void checkNfc() {
   if (mNfcAdapter == null) {
     Toast.makeText(this, R.string.cannot_find_nfc, Toast.LENGTH_SHORT).show();
   } else if (!mNfcAdapter.isEnabled()) {
     Toast.makeText(this, R.string.disabled_nfc, Toast.LENGTH_SHORT).show();
     initNfc();
   } else {
     Toast.makeText(this, R.string.nfc_is_enabled, Toast.LENGTH_SHORT).show();
     initNfc();
   }
 }
Ejemplo n.º 15
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)
            });
  }
Ejemplo n.º 16
0
  @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());
  }
  @SuppressLint({"NewApi"})
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_write_uri);
    // getActionBar().setDisplayHomeAsUpEnabled(true);

    ctx = this;
    Button btnWrite = (Button) findViewById(R.id.button);
    final TextView message = (TextView) findViewById(R.id.edit_message);

    btnWrite.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            try {
              if (mytag == null) {
                Toast.makeText(ctx, ctx.getString(R.string.error_detected), Toast.LENGTH_LONG)
                    .show();
              } else {
                // Write TNF_WELL_KNOWN with uri
                write(message.getText().toString(), mytag);
                // Write customize mime with content
                // write(message.getText().toString(),mytag);
                Toast.makeText(ctx, ctx.getString(R.string.ok_writing), Toast.LENGTH_LONG).show();
              }
            } catch (IOException e) {
              Toast.makeText(ctx, ctx.getString(R.string.error_writing), Toast.LENGTH_LONG).show();
              e.printStackTrace();
            } catch (FormatException e) {
              Toast.makeText(ctx, ctx.getString(R.string.error_writing), Toast.LENGTH_LONG).show();
              e.printStackTrace();
            }
          }
        });

    adapter = NfcAdapter.getDefaultAdapter(this);
    if (adapter == null) {
      // NFC is not available
      finish();
      return;
    }
    if (!adapter.isEnabled()) {
      // NFC is disabled
      finish();
      return;
    }
    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};
  }
 public void startReadingNfcV() {
   nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
   if (nfcAdapter == null) {
     callbackContext.error(STATUS_NO_NFC);
   } else if (!nfcAdapter.isEnabled()) {
     callbackContext.error(STATUS_NFC_DISABLED);
   } else {
     this.isReading = true;
     this.isWriting = false;
     setupForegroundDispatch(getActivity(), nfcAdapter);
   }
 }
 @TargetApi(Build.VERSION_CODES.GINGERBREAD)
 void setNfc(boolean checked) {
   if (checked) {
     useNFC = true;
     if (!mNfcAdapter.isEnabled()) {
       // goto sys pref to turn on nfc
       Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS);
       startActivity(intent);
     }
   } else {
     useNFC = false;
   }
 }
  private void initNFC() {
    nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (nfcAdapter == null) {
      Toast.makeText(this, getString(R.string.nfc_feature_not_supported_txt), Toast.LENGTH_LONG)
          .show();
      finish();
      return;
    }
    if (!nfcAdapter.isEnabled()) {
      Toast.makeText(this, getString(R.string.nfc_disabled_txt), Toast.LENGTH_LONG).show();
    } else {

    }
  }
Ejemplo n.º 21
0
  private void refreshStatus() {
    final Resources r = this.res;

    final String tip;
    if (nfcAdapter == null) tip = r.getString(R.string.tip_nfc_notfound);
    else if (nfcAdapter.isEnabled()) tip = r.getString(R.string.tip_nfc_enabled);
    else tip = r.getString(R.string.tip_nfc_disabled);

    final StringBuilder s = new StringBuilder(r.getString(R.string.app_name));

    s.append("  --  ").append(tip);
    setTitle(s);

    final CharSequence text = board.getText();
    if (text == null || board.getTag() == ContentType.HINT) showHint();
  }
 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
 void initNfcTransfer(PeerNetInfo qrData) {
   if (mNfcAdapter != null && mNfcAdapter.isEnabled() && useNFC) {
     NdefMessage msg =
         new NdefMessage(
             new NdefRecord[] {
               new NdefRecord(
                   NdefRecord.TNF_MIME_MEDIA,
                   "application/com.xconns.peerdevicenet.connector"
                       .getBytes(Charset.forName("US-ASCII")),
                   new byte[0],
                   qrData.encode().getBytes(Charset.forName("US-ASCII")))
             });
     mNfcAdapter.setNdefPushMessage(msg, this);
   }
 }
Ejemplo n.º 23
0
 protected void registerNdefPushMessageCallback() {
   NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
   if (nfcAdapter != null && nfcAdapter.isEnabled()) {
     nfcAdapter.setNdefPushMessageCallback(
         new NfcAdapter.CreateNdefMessageCallback() {
           @Override
           public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
             return new NdefMessage(
                 new NdefRecord[] {
                   NdefRecord.createUri(getShareableUri()),
                   NdefRecord.createApplicationRecord("eu.siacs.conversations")
                 });
           }
         },
         this);
   }
 }
Ejemplo n.º 24
0
 private void checkNfcEnabled() {
   Boolean nfcEnabled = mNfcAdapter.isEnabled();
   if (!nfcEnabled) {
     new AlertDialog.Builder(BeamInventoryActivity.this)
         .setTitle(getString(R.string.warning_nfc_is_off))
         .setMessage(getString(R.string.turn_on_nfc))
         .setCancelable(false)
         .setPositiveButton(
             "Update Settings",
             new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                 startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
               }
             })
         .create()
         .show();
   }
 }
Ejemplo n.º 25
0
  private void showHint() {
    final TextView board = this.board;
    final Resources res = this.res;
    final String hint;

    if (nfcAdapter == null) hint = res.getString(R.string.msg_nonfc);
    else if (nfcAdapter.isEnabled()) hint = res.getString(R.string.msg_nocard);
    else hint = res.getString(R.string.msg_nfcdisabled);

    final int padding = res.getDimensionPixelSize(R.dimen.text_middle);

    board.setPadding(padding, padding, padding, padding);
    board.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD_ITALIC));
    board.setTextSize(res.getDimension(R.dimen.text_middle));
    board.setTextColor(res.getColor(R.color.text_tip));
    board.setGravity(Gravity.CENTER_VERTICAL);
    board.setTag(ContentType.HINT);
    board.setText(Html.fromHtml(hint));
  }
Ejemplo n.º 26
0
  @Override
  protected void onResume() {
    AndroidApplication.getInstance().setCurrentActivity(this);
    LocalBroadcastManager.getInstance(this)
        .registerReceiver(
            showNextActivityListener, new IntentFilter(BroadcastIntentTypes.showNextActivity));

    if (nfcAdapter != null && nfcAdapter.isEnabled()) {
      nfcAvailable = true;
    }

    // make sure that this activity is the first one which can handle the
    // NFC tags
    if (nfcAvailable) {
      nfcAdapter.enableForegroundDispatch(this, pendingIntent, Utility.getNFCIntentFilters(), null);
    }

    super.onResume();
  }
Ejemplo n.º 27
0
  private void enableNfc() {

    if (android.os.Build.VERSION.SDK_INT >= 14) {

      // Check for available NFC Adapter
      mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
      if (mNfcAdapter == null) {
        // NFC is not available on this device
      } else {

        if (!(mNfcAdapter.isEnabled() && mNfcAdapter.isNdefPushEnabled())) {

          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder
              .setMessage(R.string.nfc_activate_required_services)
              .setTitle(R.string.message_activate_nfc)
              .setPositiveButton(
                  R.string.yes,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {

                      Toast.makeText(
                              getApplicationContext(),
                              getString(R.string.message_activate_nfc),
                              Toast.LENGTH_LONG)
                          .show();

                      startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
                    }
                  })
              .setNegativeButton(
                  R.string.no,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {}
                  })
              .create()
              .show();
        }
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_produits_aacheter);
    intentRecu = getIntent();
    scannerProduitAAcheter = (TextView) findViewById(R.id.scannerProduitAAcheter);
    prixTotal = (TextView) findViewById(R.id.prixTotal);
    listeViewAAcheter = (ListView) findViewById(R.id.listeAAcheter);
    listeViewAAcheter.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    produitsAAcheter = new ArrayList<HashMap<String, String>>();

    afficherProduitsAAcheter();

    /* On récupère va permettre à l'activité de récupérer un tag NFC */
    this.nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (nfcAdapter == null || !nfcAdapter.isEnabled()) {
      finish();
      return;
    }
  }
Ejemplo n.º 29
0
 private void initNfc() {
   nfcAdapter = NfcAdapter.getDefaultAdapter(this);
   if (nfcAdapter == null) {
     BaseHelp.ShowDialog(this, "您的设备不支持NFC,是否退出!", 0);
     // return;
   }
   if (!nfcAdapter.isEnabled()) {
     BaseHelp.ShowDialog(this, "您的设备没有打开NFC功能!", 1);
     // return;
   }
   pendingIntent =
       PendingIntent.getActivity(
           this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
   IntentFilter intentFilter = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
   intentFilter.addCategory("*//*");
   intentFilters = new IntentFilter[] {intentFilter}; // 过滤器
   techList =
       new String[][] {
         new String[] {MifareClassic.class.getName()}, new String[] {NfcA.class.getName()}
       }; // 允许扫描的标签类型
 }
Ejemplo n.º 30
0
  private String initNfcAdapter(NfcAdapter adapter) {
    StringBuilder sb = new StringBuilder();

    // nfc 功能是否开启
    if (nfcAdapter == null) {
      sb.append("支持NFC功能:" + false + "\n");
      return sb.toString();
    } else {
      sb.append("支持NFC功能:" + true + "\n");
    }
    isNfcEnable = nfcAdapter.isEnabled();
    sb.append("NFC是否开启:" + isNfcEnable + "\n");

    isNdefPushEnabled = nfcAdapter.isNdefPushEnabled();
    sb.append("Android Beam是否开启:" + isNdefPushEnabled + "\n");

    nfcAdapter.setNdefPushMessageCallback(this, this);
    nfcAdapter.setOnNdefPushCompleteCallback(this, this);

    return sb.toString();
  }