androidbroadcastreceiverintentfilterandroid-beam

Why is my BroadcastReceiver not detecting incoming files sent over android beam


Here is my manifest code for the BroadcastReceiver:

 <receiver android:name=".BeamFilter" >
        <intent-filter android:priority="99999" >
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/jpg"/>


        </intent-filter>
    </receiver>

Here is the BeamFilter class:

package com.example.test.heavykey;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.text.TextUtils;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;


public class BeamFilter extends BroadcastReceiver {
private File mParentPath;

@Override
public void onReceive(Context context, Intent intent) {
    System.out.println("Incoming Data");

}
}

and here is the code which sends the beam(from another instance of the app on a separate device)

  Intent i = new Intent(Intent.ACTION_SEND);
  i.setType("image/jpg");
  i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new    File(Environment.getExternalStorageDirectory(), "test.jpg")));
  startActivity(Intent.createChooser(i, "Send image"));

The file is successfully saved to the external directory, but I can't for the life of me figure out why my Broadcast-receiver isn't executing. Any help would be greatly appreciated.


Solution

  • android.nfc.action.NDEF_DISCOVERED is an activity action. Write an Activity, not a BroadcastReceiver.