Example usage for android.nfc NfcAdapter setBeamPushUrisCallback

List of usage examples for android.nfc NfcAdapter setBeamPushUrisCallback

Introduction

In this page you can find the example usage for android.nfc NfcAdapter setBeamPushUrisCallback.

Prototype

@java.lang.Deprecated
public void setBeamPushUrisCallback(CreateBeamUrisCallback callback, Activity activity) 

Source Link

Document

Set a callback that will dynamically generate one or more Uri s to send using Android Beam (TM).

Usage

From source file:com.example.android.beamlargefiles.BeamLargeFilesFragment.java

/**
 * Standard lifecycle event. Registers a callback for large-file transfer, by calling
 * NfcAdapter.setBeamPushUrisCallback().
 *
 * Note: Like sending NDEF messages over standard Android Beam, there is also a non-callback
 * API available. See: NfcAdapter.setBeamPushUris().
 *
 * @param savedInstanceState Saved instance state.
 *///from ww  w  .  j  a  va  2s  .  co  m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    Activity a = getActivity();

    // Setup Beam to transfer a large file. Note the call to setBeamPushUrisCallback().
    // BEGIN_INCLUDE(setBeamPushUrisCallback)
    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(a);
    if (nfc != null) {
        Log.w(TAG, "NFC available. Setting Beam Push URI callback");
        nfc.setBeamPushUrisCallback(this, a);
    } else {
        Log.w(TAG, "NFC is not available");
    }
    // END_INCLUDE(setBeamPushUrisCallback)
}

From source file:com.brandroidtools.filemanager.activities.NavigationActivity.java

/**
 * {@inheritDoc}// w  w  w.  j  a  va 2 s . c o m
 */
@Override
protected void onCreate(Bundle state) {

    if (DEBUG) {
        Log.d(TAG, "NavigationActivity.onCreate"); //$NON-NLS-1$
    }

    // Register the broadcast receiver
    IntentFilter filter = new IntentFilter();
    filter.addAction(FileManagerSettings.INTENT_SETTING_CHANGED);
    filter.addAction(FileManagerSettings.INTENT_FILE_CHANGED);
    filter.addAction(FileManagerSettings.INTENT_THEME_CHANGED);
    registerReceiver(this.mNotificationReceiver, filter);

    //Set the main layout of the activity
    setContentView(R.layout.navigation_pager);

    //Initialize nfc adapter
    NfcAdapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter != null && Build.VERSION.SDK_INT > 15) {
        mNfcAdapter.setBeamPushUrisCallback(new NfcAdapter.CreateBeamUrisCallback() {
            @Override
            public Uri[] createBeamUris(NfcEvent event) {
                List<FileSystemObject> selectedFiles = getCurrentNavigationFragment().getSelectedFiles();
                if (selectedFiles.size() > 0) {
                    List<Uri> fileUri = new ArrayList<Uri>();
                    for (FileSystemObject f : selectedFiles) {
                        //Beam ignores folders and system files
                        if (!FileHelper.isDirectory(f) && !FileHelper.isSystemFile(f)) {
                            fileUri.add(Uri.fromFile(new File(f.getFullPath())));
                        }
                    }
                    if (fileUri.size() > 0) {
                        return fileUri.toArray(new Uri[fileUri.size()]);
                    }
                }
                return null;
            }
        }, this);
    }

    //Initialize activity
    init();

    //Initialize viewPager
    initViewPager();

    //Initialize action bar
    mActionBar = getActionBar();
    initTitleActionBar();

    // Apply the theme
    applyTheme();

    // Show welcome message
    showWelcomeMsg();

    //Save state
    super.onCreate(state);
}

From source file:com.android.gallery3d.app.PhotoPage.java

@TargetApi(ApiHelper.VERSION_CODES.JELLY_BEAN)
private void setupNfcBeamPush() {
    if (!ApiHelper.HAS_SET_BEAM_PUSH_URIS)
        return;//from   w ww.j a  v a  2  s. c om

    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(mActivity);
    if (adapter != null) {
        adapter.setBeamPushUris(null, mActivity);
        /// M: [BEHAVIOR.MODIFY] nfc @{
        if (FeatureConfig.SUPPORT_MTK_BEAM_PLUS) {
            adapter.setMtkBeamPushUrisCallback(new CreateBeamUrisCallback() {
                @Override
                public Uri[] createBeamUris(NfcEvent event) {
                    return mNfcPushUris;
                }
            }, mActivity);
        } else {
            adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
                @Override
                public Uri[] createBeamUris(NfcEvent event) {
                    return mNfcPushUris;
                }
            }, mActivity);
        }
        /*adapter.setBeamPushUrisCallback(new CreateBeamUrisCallback() {
         @Override
         public Uri[] createBeamUris(NfcEvent event) {
         return mNfcPushUris;
         }
         }, mActivity);*/
        /// @}
    }
}