kukuk
App-Anbieter (kostenlos)
- 29
Ich habe einen Code übernommen zum NFC File Transfer. Jetzt habe ich das Probleme, wenn ich eine Datei übertrage und diese im Ursprungsformat übertrage z.b. .zip Stürzt beim EMpfänger die Systemapp NFC ab. Die Datei ist allerdings übertragen worden. Benenne ich die zu übertragenden Datei in .png um funktioniert der Transfer.
Kann man das irgendwie korrigieren?
Kann man das irgendwie korrigieren?
Code:
public void onCreate(){
PackageManager pm = getActivity().getPackageManager();
// Check whether NFC is available on device
if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
// NFC is not available on the device.
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(rootView.getContext(), "The device does not has NFC hardware.",
Toast.LENGTH_SHORT).show();
}
});
}
// Check whether device is running Android 4.1 or higher
else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
// Android Beam feature is not supported.
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(rootView.getContext(), "Android Beam is not supported.",
Toast.LENGTH_SHORT).show();
}
});
}
else {
// NFC and Android Beam file transfer is supported.
//Toast.makeText(rootView.getContext(), "Android Beam is supported on your device.",
// Toast.LENGTH_SHORT).show();
}
sendFile();
}
public void sendFile() {
try {
nfcAdapter = NfcAdapter.getDefaultAdapter(rootView.getContext());
// Check whether NFC is enabled on device
if (!nfcAdapter.isEnabled()) {
// NFC is disabled, show the settings UI
// to enable NFC
Toast.makeText(rootView.getContext(), "Please enable NFC.",
Toast.LENGTH_SHORT).show();
startActivity(new Intent(Settings.ACTION_NFC_SETTINGS));
}
// Check whether Android Beam feature is enabled on device
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
if (!nfcAdapter.isNdefPushEnabled()) {
// Android Beam is disabled, show the settings UI
// to enable Android Beam
Toast.makeText(rootView.getContext(), "Please enable Android Beam.",
Toast.LENGTH_SHORT).show();
startActivity(new Intent(Settings.ACTION_NFCSHARING_SETTINGS));
} else {
// NFC and Android Beam both are enabled
// File to be transferred
// For the sake of this tutorial I've placed an image
// named 'wallpaper.png' in the 'Pictures' directory
String fileName = "abzk_file_transfer.png";
// Retrieve the path to the user's public pictures directory
File fileDirectory = new File(Environment.getExternalStorageDirectory() + "/Arbeitszeit-Kalkulator Temp");
// Create a new file using the specified directory and name
File fileToTransfer = new File(fileDirectory, fileName);
fileToTransfer.setReadable(true, false);
nfcAdapter.setBeamPushUris(
new Uri[]{Uri.fromFile(fileToTransfer)}, getActivity());
}
}
} catch (Exception e) {
}
}