当前位置: 首页>>代码示例>>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;未经允许,请勿转载。