图片我有,当我点击一个按钮,通过NFC的图像发送到另一智能手机的方法。代码似乎是正确的,执行到达代码的最后一行,但没有任何反应。两款智能手机都有NFC和Android Beam。下面是代码:无法发送和使用NFC
public void sendFile(View view){
nfcAdapter=NfcAdapter.getDefaultAdapter(this);
if(!nfcAdapter.isEnabled()){
Toast.makeText(this,"Please enable NFC",Toast.LENGTH_SHORT).show();
startActivity(new Intent(Settings.ACTION_NFC_SETTINGS));
} else if (!nfcAdapter.isNdefPushEnabled()) {
Toast.makeText(this,"Please enable android beam",Toast.LENGTH_SHORT).show();
startActivity(new Intent(Settings.ACTION_NFCSHARING_SETTINGS));
} else {
//If we got here, Nfc and Android beam are enabled
Toast.makeText(this,"Ok",Toast.LENGTH_SHORT).show();
String fileName="test.jpg";
File fileDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File fileToTransfer =new File(fileDirectory,fileName);
Toast.makeText(this,"Tutto Ok2",Toast.LENGTH_SHORT).show();
fileToTransfer.setReadable(true,false);
Uri fileUri=Uri.fromFile(fileToTransfer);
if(fileUri==null){
Toast.makeText(this,"File not found",Toast.LENGTH_SHORT).show();
} else{
//If we got here, the app has found the image and is ready to send it
Toast.makeText(this,"Tutto Ok3",Toast.LENGTH_SHORT).show();
//Send the image
nfcAdapter.setBeamPushUris(new Uri[]{Uri.fromFile(fileToTransfer)},this);
}
}
任何帮助,将不胜感激
即使使用此代码,NFC不work..the图像存在,但它不会把它(对LG G2和Nexus 5测试)的问题(当然,我改变了资源的路径) –
编辑:正如我的第一个代码,它的工作原理1个超时的10 ..我不明白为什么 –
什么步骤不工作?当触摸或在传输过程中或...您是否登录logcat? – LaurentY