【发布时间】:2014-12-26 11:44:04
【问题描述】:
我正在尝试使用 Android Beam 在应用程序之间传输大文件。发送部分运行良好,文件出现在“beam/”目录中。通知状态栏显示“Beam 完成”。但是,在文件重命名到 beam/ 目录后,接收应用程序不会收到通知,并且 onNewIntent() 永远不会在接收端被调用。意图过滤器缺少什么?是否可以在使用 createBeamUris() 时指定 Android 应用程序记录? TIA
// 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());
}
}
【问题讨论】:
标签: android file nfc intentfilter transfer