类android.nfc.NfcEvent源码实例Demo

下面列出了怎么用android.nfc.NfcEvent的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Camera2   文件: CameraActivity.java
private void setupNfcBeamPush()
{
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mAppContext);
    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);
}
 
/**
 * Callback for Beam events (large file version). The return value here should be an array of
 * content:// or file:// URIs to send.
 *
 * Note that the system must have read access to whatever URIs are provided here.
 *
 * @param nfcEvent NFC event which triggered callback
 * @return URIs to be sent to remote device
 */
// BEGIN_INCLUDE(createBeamUris)
@Override
public Uri[] createBeamUris(NfcEvent nfcEvent) {
    Log.i(TAG, "Beam event in progress; createBeamUris() called.");
    // Images are served using a content:// URI. See AssetProvider for implementation.
    Uri photoUri = Uri.parse(CONTENT_BASE_URI + FILENAME);
    Log.i(TAG, "Sending URI: " + photoUri);
    return new Uri[] {photoUri};
}
 
private void setBeamMessage() {
  NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
  nfcAdapter.setNdefPushMessageCallback(
    new NfcAdapter.CreateNdefMessageCallback() {
      public NdefMessage createNdefMessage(NfcEvent event) {
        String payload = "Beam me up, Android!\n\n" +
                         "Beam Time: " + System.currentTimeMillis();
        NdefMessage message = createMessage(payload);
        return message;
      }
    }, this);
}
 
源代码4 项目: delion   文件: BeamCallback.java
@Override
public void onNdefPushComplete(NfcEvent event) {
    if (mErrorRunnableIfBeamSent != null) {
        Handler h = new Handler(Looper.getMainLooper());
        h.postDelayed(mErrorRunnableIfBeamSent, TOAST_ERROR_DELAY_MS);
        mErrorRunnableIfBeamSent = null;
    }
}
 
源代码5 项目: AndroidChromium   文件: BeamCallback.java
@Override
public void onNdefPushComplete(NfcEvent event) {
    if (mErrorRunnableIfBeamSent != null) {
        Handler h = new Handler(Looper.getMainLooper());
        h.postDelayed(mErrorRunnableIfBeamSent, TOAST_ERROR_DELAY_MS);
        mErrorRunnableIfBeamSent = null;
    }
}
 
/**
 * Callback for Beam events (large file version). The return value here should be an array of
 * content:// or file:// URIs to send.
 *
 * Note that the system must have read access to whatever URIs are provided here.
 *
 * @param nfcEvent NFC event which triggered callback
 * @return URIs to be sent to remote device
 */
// BEGIN_INCLUDE(createBeamUris)
@Override
public Uri[] createBeamUris(NfcEvent nfcEvent) {
    Log.i(TAG, "Beam event in progress; createBeamUris() called.");
    // Images are served using a content:// URI. See AssetProvider for implementation.
    Uri photoUri = Uri.parse(CONTENT_BASE_URI + FILENAME);
    Log.i(TAG, "Sending URI: " + photoUri);
    return new Uri[] {photoUri};
}
 
源代码7 项目: 365browser   文件: BeamCallback.java
@Override
public void onNdefPushComplete(NfcEvent event) {
    if (mErrorRunnableIfBeamSent != null) {
        Handler h = new Handler(Looper.getMainLooper());
        h.postDelayed(mErrorRunnableIfBeamSent, TOAST_ERROR_DELAY_MS);
        mErrorRunnableIfBeamSent = null;
    }
}
 
源代码8 项目: Slide   文件: BaseActivity.java
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    if (shareUrl != null) {
        return new NdefMessage(new NdefRecord[]{
                NdefRecord.createUri(shareUrl)
        });
    }
    return null;
}
 
源代码9 项目: android-sdk   文件: InvoiceActivity.java
@Override
public NdefMessage createNdefMessage(NfcEvent event) {

    if (mInvoice != null && mInvoice.getPaymentUrls() != null && mInvoice.getPaymentUrls().getBIP72b() != null) {
        return new NdefMessage(new NdefRecord[]{
                NdefRecord.createUri(mInvoice.getPaymentUrls().getBIP72())
        });
    }
    return null;
}
 
@Override
public void onNdefPushComplete(NfcEvent nfcEvent) {
	Log.d(TAG, "Ndef push completed");
	
	runOnUiThread(new Runnable() {
		public void run() {
			onNdefPushCompleted();
		}	
	});
}
 
源代码11 项目: ploggy   文件: ActivitySendIdentityByNfc.java
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    try {
        String payload = Json.toJson(Data.getInstance().getSelf().mPublicIdentity);
        return new NdefMessage(
                new NdefRecord[] {
                        NdefRecord.createMime(NFC_MIME_TYPE, payload.getBytes()),
                        NdefRecord.createApplicationRecord(NFC_AAR_PACKAGE_NAME) });
    } catch (Utils.ApplicationError e) {
        Log.addEntry(LOG_TAG, "failed to create outbound NFC message");
    }
    return null;
}
 
源代码12 项目: ploggy   文件: ActivitySendIdentityByNfc.java
@Override
public void onNdefPushComplete(NfcEvent nfcEvent) {
    final Context finalContext = this;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Vibrator vibe = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
            vibe.vibrate(100);
            Toast.makeText(finalContext, R.string.prompt_nfc_push_complete, Toast.LENGTH_LONG).show();
        }});
}
 
源代码13 项目: geopaparazzi   文件: GpsDataListActivity.java
@Override
public NdefMessage createNdefMessage(NfcEvent event) {

    try {
        List<LogMapItem> logsList = DaoGpsLog.getGpslogs();
        SerializableLogs logs = new SerializableLogs();
        for (int i = 0; i < logsList.size(); i++) {
            LogMapItem logMapItem = logsList.get(i);
            if (logMapItem.isVisible()) {
                Line line = DaoGpsLog.getGpslogAsLine(logMapItem.getLogID(), -1);
                logs.addLog(logMapItem, line);
            }
        }
        byte[] logBytes = Utilities.serializeObject(logs);

        NdefMessage msg = new NdefMessage(NdefRecord.createMime(
                logSendingMimeType, logBytes)
                /**
                 * The Android Application Record (AAR) is commented out. When a device
                 * receives a push with an AAR in it, the application specified in the AAR
                 * is guaranteed to run. The AAR overrides the tag dispatch system.
                 * You can add it back in to guarantee that this
                 * activity starts when receiving a beamed message. For now, this code
                 * uses the tag dispatch system.
                 */
                //,NdefRecord.createApplicationRecord("com.examples.nfcbeam")
        );
        return msg;
    } catch (IOException e) {
        GPLog.error(this, "Error in sending logs.", e);//NON-NLS
    }
    return null;
}
 
源代码14 项目: geopaparazzi   文件: GpsDataListActivity.java
@Override
public void onNdefPushComplete(NfcEvent event) {
    //This callback happens on a binder thread, don't update
    // the UI directly from this method.
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            GPDialogs.infoDialog(GpsDataListActivity.this, getString(R.string.logs_sent), null);
        }
    });
}
 
源代码15 项目: ShadowsocksRR   文件: ProfileManagerActivity.java
@Override
public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
    return new NdefMessage(new NdefRecord[]{new NdefRecord(NdefRecord.TNF_ABSOLUTE_URI, nfcShareItem, new byte[]{}, nfcShareItem)});
}
 
源代码16 项目: Maying   文件: ProfileManagerActivity.java
@Override
public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
    return new NdefMessage(new NdefRecord[]{new NdefRecord(NdefRecord.TNF_ABSOLUTE_URI, nfcShareItem, new byte[]{}, nfcShareItem)});
}
 
源代码17 项目: NaviBee   文件: AddFriendQRActivity.java
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    //When creating an NdefMessage we need to provide an NdefRecord[]
    return new NdefMessage(createRecords());
}
 
源代码18 项目: NaviBee   文件: AddFriendQRActivity.java
@Override
public void onNdefPushComplete(NfcEvent event) {
}
 
源代码19 项目: Slide   文件: BaseActivity.java
@Override
public void onNdefPushComplete(NfcEvent arg0) {
}
 
源代码20 项目: android-nfc-lib   文件: MainActivity.java
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    return new NfcMessageUtilityImpl().createText("Message to beam");
}
 
源代码21 项目: droid-stealth   文件: MorphingFragment.java
@Override
public Uri[] createBeamUris(NfcEvent nfcEvent) {
	return new Uri[] { Uri.fromFile(mCurrentApp) };
}
 
源代码22 项目: android-sdk   文件: InvoiceActivity.java
@Override
public void onNdefPushComplete(NfcEvent event) {
    // Pass
}
 
源代码23 项目: geopaparazzi   文件: ExportActivity.java
@Override
public Uri[] createBeamUris(NfcEvent nfcEvent) {
    GPLog.addLogEntry(this, "URI SENT: " + mFileUris[0]); //NON-NLS
    return mFileUris;
}
 
源代码24 项目: android-nfc-lib   文件: NfcActivity.java
/**
 * Method called when attempting to beam.
 *
 * @param event
 *         delivered by system
 *
 * @return an NFC Message to auto-pair bluetooth, or Test text when no bluetooth is present.
 */
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    return new NfcMessageUtilityImpl().createText("You're seeing this message because you have not overridden the createNdefMessage(NfcEvent event) in your activity.");
}