當前位置: 首頁>>代碼示例>>Java>>正文


Java NfcEvent類代碼示例

本文整理匯總了Java中android.nfc.NfcEvent的典型用法代碼示例。如果您正苦於以下問題:Java NfcEvent類的具體用法?Java NfcEvent怎麽用?Java NfcEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NfcEvent類屬於android.nfc包,在下文中一共展示了NfcEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createNdefMessage

import android.nfc.NfcEvent; //導入依賴的package包/類
/**
 * Implementation for the CreateNdefMessageCallback interface
 */
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    Time time = new Time();
    time.setToNow();
    String text = ("Beam me up!\n\n" +
            "Beam Time: " + time.format("%H:%M:%S"));
    NdefMessage msg = new NdefMessage(NdefRecord.createMime(
            "application/com.example.android.beam", text.getBytes())
     /**
      * 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.example.android.beam")
    );
    return msg;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:24,代碼來源:Beam.java

示例2: onCreate

import android.nfc.NfcEvent; //導入依賴的package包/類
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    cinemas = DBHelper.getInstance(getContext()).getCinemas();

    watcher = new Gson().fromJson(getArguments().getString("watcher"), Watcher.class);

    nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
    if(nfcAdapter != null) {
        nfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
            @Override
            public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
                return new NdefMessage(
                        new NdefRecord[] {
                                NdefRecord.createUri(BuildConfig.SERVER_BASE_URL + "w/" + watcher.getID()),
                                NdefRecord.createApplicationRecord(BuildConfig.APPLICATION_ID)
                        }
                );
            }
        }, getActivity());
    }
}
 
開發者ID:jpelgrom,項目名稱:Movie-Notifier-Android,代碼行數:24,代碼來源:WatcherBottomSheet.java

示例3: registerNfcCallback

import android.nfc.NfcEvent; //導入依賴的package包/類
public void registerNfcCallback(Activity activity) {
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (nfcAdapter != null) {
        // Register callback
        nfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
            @Override
            public NdefMessage createNdefMessage(NfcEvent event) {
                return new NdefMessage(
                    new NdefRecord[] {
                        NdefRecord.createMime(
                            "application/vnd.com.pgrenaud.android.p2p.beam",
                            getPeerRepository().encode().getBytes()
                        )
                    }
                );
            }
        }, activity);

        Log.d("PeerService", "NdefPushMessageCallback registered");
    }
}
 
開發者ID:pgrenaud,項目名稱:p2p-android-sdk,代碼行數:22,代碼來源:PeerService.java

示例4: setAppDataPushMessageCallbackIfAvailable

import android.nfc.NfcEvent; //導入依賴的package包/類
public static boolean setAppDataPushMessageCallbackIfAvailable(Activity activity, final CreateNfcAppDataCallback callback) {
	NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity);
	if (adapter == null) {
		return false;
	}
	final String packageName = activity.getPackageName();
	adapter.setNdefPushMessageCallback(new CreateNdefMessageCallback() {

		@Override
		public NdefMessage createNdefMessage(NfcEvent event) {
			byte[] appData = callback.createNfcAppData();
			if (appData == null) {
				return null;
			}
			NdefRecord[] records = new NdefRecord[] { createMimeRecord("application/" + packageName, appData),
					NdefRecord.createApplicationRecord(packageName) };
			return new NdefMessage(records);
		}

	}, activity);
	return true;
}
 
開發者ID:sysdharma,項目名稱:py-eventos-android,代碼行數:23,代碼來源:NfcSenderUtils.java

示例5: setAppDataPushMessageCallbackIfAvailable

import android.nfc.NfcEvent; //導入依賴的package包/類
public static boolean setAppDataPushMessageCallbackIfAvailable(Activity activity, final CreateNfcAppDataCallback callback) {
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity);
    if (adapter == null) {
        return false;
    }
    final String packageName = activity.getPackageName();
    adapter.setNdefPushMessageCallback(new CreateNdefMessageCallback() {

        @Override
        public NdefMessage createNdefMessage(NfcEvent event) {
            byte[] appData = callback.createNfcAppData();
            if (appData == null) {
                return null;
            }
            NdefRecord[] records = new NdefRecord[]{createMimeRecord("application/" + packageName, appData),
                    NdefRecord.createApplicationRecord(packageName)};
            return new NdefMessage(records);
        }

    }, activity);
    return true;
}
 
開發者ID:OpnTec,項目名稱:ots15-companion,代碼行數:23,代碼來源:NfcSenderUtils.java

示例6: createBeamUris

import android.nfc.NfcEvent; //導入依賴的package包/類
@Override
public Uri[] createBeamUris(NfcEvent event) {
    String transferFile = FullscreenActivity.songfilename;
    File extDir;
    if (FullscreenActivity.whichSongFolder.equals(getString(R.string.mainfoldername))) {
        extDir =FullscreenActivity.dir;
    } else {
        extDir = new File(FullscreenActivity.dir + "/" + FullscreenActivity.whichSongFolder + "/");
    }
    File requestFile = new File(extDir, transferFile);
    boolean b = requestFile.setReadable(true, false);
    if (!b) {
        // Get a URI for the File and add it to the list of URIs
        Uri fileUri = Uri.fromFile(requestFile);
        if (fileUri != null) {
            mFileUris[0] = fileUri;
        } else {
            Log.e("My Activity", "No File URI available for file.");
        }
        return mFileUris;
    } else {
        return null;
    }
}
 
開發者ID:thebigg73,項目名稱:OpenSongTablet,代碼行數:25,代碼來源:StageMode.java

示例7: setupNfcBeamPush

import android.nfc.NfcEvent; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
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);
}
 
開發者ID:jameliu,項目名稱:Camera2,代碼行數:22,代碼來源:CameraActivity.java

示例8: createNdefMessage

import android.nfc.NfcEvent; //導入依賴的package包/類
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    return new NdefMessage(
            new NdefRecord[] { NdefRecord.createMime(
                    "application/vnd.co.loubo.icicle", this.encodedNodeRef.getBytes(Charset.forName("US-ASCII")))
                    /**
                     * 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.example.android.beam")
            });
}
 
開發者ID:louboco,項目名稱:Icicle,代碼行數:17,代碼來源:OpenReferenceActivity.java

示例9: createNdefMessage

import android.nfc.NfcEvent; //導入依賴的package包/類
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    // NFC should be auto granted, but doesn't hurt to check.
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.NFC)
            != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.NFC}, NFC_PERMISSIONS);
    }

    String url = URLEncoder.encodeBuild(this, currentBuild);
    NdefMessage msg = new NdefMessage(
            new NdefRecord[] { createMime(
                    "application/vnd.com.jamieadkins.heistr", url.getBytes())
                    ,NdefRecord.createApplicationRecord("com.jamieadkins.heistr")
            });
    return msg;
}
 
開發者ID:jamieadkins95,項目名稱:Heistr,代碼行數:19,代碼來源:EditBuildActivity.java

示例10: start

import android.nfc.NfcEvent; //導入依賴的package包/類
@Override
public void start() {
    if (!nfcAdapter.isEnabled())
    {
        this.activity.startActivity(new Intent(Settings.ACTION_NFC_SETTINGS));
        return;
    }

    this.nfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
        @Override
        public NdefMessage createNdefMessage(NfcEvent event) {
            byte[] payload = new byte[Preferences.getInstance().getPayloadSize()];
            Arrays.fill(payload, (byte) 1);
            return new NdefMessage(
                    new NdefRecord[] { NdefRecord.createMime(
                            MIMETYPE, payload)
                    });
        }
    },this.activity);
}
 
開發者ID:dcale,項目名稱:AndroidCommunicationBenchmark,代碼行數:21,代碼來源:NFCServer.java

示例11: setupNfcBeamPush

import android.nfc.NfcEvent; //導入依賴的package包/類
@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);
}
 
開發者ID:asm-products,項目名稱:nexus-camera,代碼行數:22,代碼來源:CameraActivity.java

示例12: createNdefMessage

import android.nfc.NfcEvent; //導入依賴的package包/類
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
    if (currentUri == null) { // || !isStarted) ignore ...
        if (Log.logErrorMessages()) {
            Log.e(LOG_TAG, "I have no URI, can't send NFC message. ");
        }
        return null; // don't provide a message
    }
    if (Log.logDebugMessages()) {
        Log.d(LOG_TAG, "NFC transaction is taking place ...");
    }
    NdefMessage msg = new NdefMessage(
            new NdefRecord[]{
                    NdefRecord.createUri(currentUri)
            });
    return msg;
}
 
開發者ID:Blaubot,項目名稱:Blaubot,代碼行數:18,代碼來源:BlaubotNFCBeacon.java

示例13: initNFC

import android.nfc.NfcEvent; //導入依賴的package包/類
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);

}
 
開發者ID:dingyu,項目名稱:Dingyu,代碼行數:21,代碼來源:MainTimeLineParentActivity.java

示例14: setAppDataPushMessageCallbackIfAvailable

import android.nfc.NfcEvent; //導入依賴的package包/類
/**
 * Call this method in an Activity, between onCreate() and onDestroy(), to make its content sharable using Android Beam if available. MIME type of the data
 * to share will be "application/" followed by the app's package name. Declare it in your Manifest's intent filters as the data type with an action of
 * android.nfc.action.NDEF_DISCOVERED to handle the NFC Intents on the receiver side.
 *
 * @return true if NFC is available and the content was made available, false if not.
 */
public static boolean setAppDataPushMessageCallbackIfAvailable(Activity activity, final CreateNfcAppDataCallback callback) {
	NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity);
	if (adapter == null) {
		return false;
	}
	final String packageName = activity.getPackageName();
	adapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {

		@Override
		public NdefMessage createNdefMessage(NfcEvent event) {
			byte[] appData = callback.createNfcAppData();
			if (appData == null) {
				return null;
			}
			NdefRecord[] records = new NdefRecord[]{createMimeRecord("application/" + packageName, appData),
					NdefRecord.createApplicationRecord(packageName)};
			return new NdefMessage(records);
		}

	}, activity);
	return true;
}
 
開發者ID:cbeyls,項目名稱:fosdem-companion-android,代碼行數:30,代碼來源:NfcUtils.java

示例15: activateNFCSharing

import android.nfc.NfcEvent; //導入依賴的package包/類
@SuppressLint("NewApi")
public void activateNFCSharing(Activity activity) {
    if (mShAIReHttpServer != null && mShAIReHttpServer.getRealUrl() != null) {
        // NFC
        if (android.os.Build.VERSION.SDK_INT > 14) {
            NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
            if (nfcAdapter != null) {
                nfcAdapter.setNdefPushMessageCallback(
                        new NfcAdapter.CreateNdefMessageCallback() {

                            @Override
                            public NdefMessage createNdefMessage(
                                    NfcEvent event) {
                                return new NdefMessage(
                                        new NdefRecord[]{NdefRecord.createUri(Uri
                                                .parse(mShAIReHttpServer
                                                        .getRealUrl()))});
                            }
                        }, activity);
            }
        }
    }
}
 
開發者ID:guiguito,項目名稱:AIRShare,代碼行數:24,代碼來源:ShaireService.java


注:本文中的android.nfc.NfcEvent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。