Compartir a través de


NfcAdapter.SetBeamPushUris(Uri[], Activity) Method

Definition

Set one or more Uris to send using Android Beam (TM).

[Android.Runtime.Register("setBeamPushUris", "([Landroid/net/Uri;Landroid/app/Activity;)V", "")]
public void SetBeamPushUris (Android.Net.Uri[]? uris, Android.App.Activity? activity);
[<Android.Runtime.Register("setBeamPushUris", "([Landroid/net/Uri;Landroid/app/Activity;)V", "")>]
member this.SetBeamPushUris : Android.Net.Uri[] * Android.App.Activity -> unit

Parameters

uris
Uri[]

an array of Uri(s) to push over Android Beam

activity
Activity

activity for which the Uri(s) will be pushed

Attributes

Remarks

Set one or more Uris to send using Android Beam (TM). Every Uri you provide must have either scheme 'file' or scheme 'content'.

For the data provided through this method, Android Beam tries to switch to alternate transports such as Bluetooth to achieve a fast transfer speed. Hence this method is very suitable for transferring large files such as pictures or songs.

The receiving side will store the content of each Uri in a file and present a notification to the user to open the file with a android.content.Intent with action android.content.Intent#ACTION_VIEW. If multiple URIs are sent, the android.content.Intent will refer to the first of the stored files.

This method may be called at any time before Activity#onDestroy, but the URI(s) are only made available for Android Beam when the specified activity(s) are in resumed (foreground) state. The recommended approach is to call this method during your Activity's Activity#onCreate - see sample code below. This method does not immediately perform any I/O or blocking work, so is safe to call on your main thread.

#setBeamPushUris and #setBeamPushUrisCallback have priority over both #setNdefPushMessage and #setNdefPushMessageCallback.

If #setBeamPushUris is called with a null Uri array, and/or #setBeamPushUrisCallback is called with a null callback, then the Uri push will be completely disabled for the specified activity(s).

Code example:

protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
                if (nfcAdapter == null) return;  // NFC not available on this device
                nfcAdapter.setBeamPushUris(new Uri[] {uri1, uri2}, this);
            }

And that is it. Only one call per activity is necessary. The Android OS will automatically release its references to the Uri(s) and the Activity object when it is destroyed if you follow this pattern.

If your Activity wants to dynamically supply Uri(s), then set a callback using #setBeamPushUrisCallback instead of using this method.

<p class="note">Do not pass in an Activity that has already been through Activity#onDestroy. This is guaranteed if you call this API during Activity#onCreate.

<p class="note">If this device does not support alternate transports such as Bluetooth or WiFI, calling this method does nothing.

<p class="note">Requires the android.Manifest.permission#NFC permission.

Java documentation for android.nfc.NfcAdapter.setBeamPushUris(android.net.Uri[], android.app.Activity).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to