我試圖使用Android Beam在應用程序之間傳輸大文件。發送部分運行良好,文件出現在'beam /'目錄中。通知狀態欄顯示「Beam complete」。但是,在文件重命名爲beam /目錄並且onNewIntent()永遠不會在接收端調用後,接收應用程序不會收到通知。我意圖過濾器丟失了什麼?還有可能在使用createBeamUris()時指定Android應用程序記錄? TIA如何使用Android NFC傳輸文件
// sending app
nfcAdapter.setBeamPushUrisCallback(this, this);
...
@Override
public Uri[] createBeamUris(NfcEvent event) { // send files
File dir = Environment.getExternalStorageDirectory();
File file = new File(dir, "test.txt");
file.setReadable(true, false); // readable=true, ownerOnly=false
return new Uri[] { Uri.fromFile(file) };
}
我的Manifest.xml:
<activity
android:name=".BeamDemo2"
android:label="@string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.txt" />
<data android:host="*" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/com.example.beamdemo2" />
</intent-filter>
</activity>
我自己也嘗試enableForegroundDispatch():
@Override
public void onResume() {
super.onResume();
try {
PendingIntent mPendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndefIntent = new IntentFilter("android.intent.action.VIEW");
ndefIntent.addCategory("android.intent.category.DEFAULT");
ndefIntent.addDataType("*/*");
IntentFilter[]mIntentFilters = new IntentFilter[] { ndefIntent };
String[][] mNFCTechLists = new String[][] { new String[] { NfcF.class.getName() } };
mNfcAdapter.enableForegroundDispatch(this, mPendingIntent, mIntentFilters, mNFCTechLists);
} catch (Exception e) {
Log.e("onResume", e.toString());
}
}