圖片我有,當我點擊一個按鈕,通過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