설명서를 몇 번 읽었으며 예제 코드를 살펴 봤지만 잘못된 것을 파악할 수 없습니다.Android Beam/NFC에서 내가 보낸 기록을 수신하지 않는 이유는 무엇입니까?
두 개의 장치를 함께 배치하면 빔 화면이 나타나고 탭핑되지만 아무 것도 보내지지 않고 아무 브레이크 포인트도 맞지 않습니다. 다음은 제 코드입니다. 아무 것도 다른 기기로 보내지는 이유를 알아내는 데 도움이됩니다. 편집자에서 나는 BeamFileActivity
에있는 모든 것이 실행된다는 것을 볼 수 있습니다. 나는 수신 장치에서 MainActivity
의 중단 점을 보지 못했습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
의 AndroidManifest.xml :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp">
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<application
android:name=".MainActivity"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<meta-data
android:name="QUERY_LOG"
android:value="false" />
<meta-data
android:name="DOMAIN_PACKAGE_NAME"
android:value="com.myapp.domain" />
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="com.google.android.apps.drive.DRIVE_OPEN" />
<action android:name="com.google.android.apps.drive.DRIVE_SAVE" />
<data android:mimeType="application/vnd.google-apps.drive-sdk.111111111" />
<data android:mimeType="application/vnd.google-apps.spreadsheet" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="vnd.android.nfc"
android:host="ext"
android:pathPrefix="/com.myapp:SpreadsheetDom"/>
</intent-filter>
</activity>
<activity
android:name=".dialog.BeamFileActivity"
android:label="@string/title_activity_beam_file"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.myapp.MainActivity" />
</activity>
</application>
MainActivity :이 난 단지 내가 관련이 생각하는 방법을 포함하고있어, 빔 의도를받을 것입니다.
BeamFileActivity : 이것은 데이터를 전송하기위한 지침을 표시하고 실제 광선을 표시하는 별도의 활동입니다.
private void initFileToBeam(Long spreadsheetId) {
try {
List<SpreadsheetDom> spreadsheets = db.getSpreadsheetDao().queryForEq(SpreadsheetDom.SPREADSHEET_ID_NAME, spreadsheetId);
if(spreadsheets != null && spreadsheets.size() > 0) {
fileToBeam = spreadsheets.get(0);
}
} catch(SQLException e) {
ErrorDialog ed = new ErrorDialog(this, "Unable to beam current collection.");
ed.show();
}
}
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
if(fileToBeam == null) {
Long spreadsheetId = Settings.getInstance().get(SettingKey.CURRENT_SPREADSHEET).getValue();
initFileToBeam(spreadsheetId);
}
NdefMessage msg = null;
try {
msg = new NdefMessage(
new NdefRecord[]{
new NdefRecord(NdefRecord.TNF_EXTERNAL_TYPE, "application/com.myapp:SpreadsheetDom".getBytes(), new byte[0], fileToBeam.toBytes()),
//NdefRecord.createExternal("com.myapp", "spreadsheetdom", fileToBeam.toBytes()),
NdefRecord.createApplicationRecord("com.myapp")
});
} catch(IOException e) {
String textMessage = "Unable to transfer collection: " + e.getMessage();
msg = new NdefMessage(
new NdefRecord[]{
NdefRecord.createMime("text/plain", textMessage.getBytes()),
NdefRecord.createApplicationRecord("com.myapp")
});
}
return msg;
}
@Override
public void onResume() {
super.onResume();
Intent exportFileIntent = getIntent();
Long spreadsheetId = exportFileIntent.getLongExtra(Constants.EXTRA_SPREADSHEET_ID, Database.INVALID_ID);
initFileToBeam(spreadsheetId);
mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (mNfcAdapter == null) {
Toast.makeText(this, "NFC is not available", Toast.LENGTH_LONG).show();
finish();
return;
}
// Register callback
mNfcAdapter.setNdefPushMessageCallback(this, this);
}
정말이 모든 예제와 문서 here, here 및 here
내가 제안한 변경 사항을 적용했지만 여전히 작동하지 않습니다. 간단한 텍스트 메시지로 전환하고 형식을 TNF_MIME_MEDIA로 변경하여 전송할 데이터를 가져올 수있었습니다. 그러나 내 spreadsheetdom으로 다시 전환했을 때 작업이 중단되었으며 문제가 크기 일 수 있습니다. 나는 spreadsheetdom을 bytearrayoutputstream으로 변환하고 그 객체의 9 개의 버퍼를 채 웁니다. 그게 많든 아니든, 나는 많이 모른다.TNF_MIME_MEDIA 메시지로 보낼 수있는 데이터의 양에는 제한이 있습니까? – Hardy
@Hardy 데이터 blob은 얼마나 큽니다 (바이트 단위)? 외부 유형이 간단한 텍스트 메시지로 작동합니까? –
외부 유형을 시도하면 항상 플레이 스토어로 이동하고 앱을 열지 않습니다. byteAlrayOutputStream.size()보고 322,000 – Hardy