Search This Blog

Sunday 1 July 2012

Android beam - Now tap your phone to share with simple code

Exciting Weekend friends after Android Jelly Bean Release now coming back to my blog with this interesting post for Android Beam Feature of Jelly Bean.

Android Beam with Jelly Bean comes up with a great opportunity for creative app developers. The Google updated the developer.android.com with latest release of Android 4.1. (API Level 16)

See here how can you use the Android Beam to change the world of sharing.

Android Beam now supports the large payloads for images and audio/video transfers.

You can use the following method to send the multiple Uris through android beam.

public void setBeamPushUris (Uri[] uris, Activity activity)


Parameters
urisan array of Uri(s) to push over Android Beam
activityactivity for which the Uri(s) will be pushed


The API automatically select the best way to transfer the data and the receiver will receive the content of each Uri in a file and present a notification to the user to open a file with a intent with a ACTION_VIEW.

You can simply get the NfcAdapter object to call this method in your activity onCreate method.


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);
 }

Note : If device does not support alternate transports such as Bluetooth or WiFI, calling this method does nothing. 


You also need to define the following permission in your app manifest file.


android.permission.NFC







1 comment:

  1. Whoa! This blog looks exactly like my old one! It's on a entirely different subject but it has pretty much the same page layout and design. Excellent choice of colors!innovation management system

    ReplyDelete