Understanding AllShare Framework SDK
With the increase in numbers of smart devices, the data is replicated in all of the smart devices. Because of replication of contents we need more storage to store our contents. If we want to access the same file in a device by another device then it becomes painful to copy contents from one device to another device. To solve this problem, Samsung developed AllShare Framework. AllShare Framework makes the content to access anywhere anytime within the AllShare enabled network.
AllShare can be used for the following purposes:
1. Sharing media files like videos, audios and photos. Media content can be streamed from the storage of the device or web server
2. Controlling smart devices like Smart TV,Smart Home Appliances remotely
3. Instant mirroring displays
AllShare framework is pre-installed in Samsung Galaxy S4, Samsung Home Sync, Samsung Galaxy S3, Samsung Note 10.1, Samsung Note 2, and Samsung Galaxy Camera Series. It will be pre-installed in all new Samsung devices.
That was about AllShare Framework. Now as a developer how do we get started ? Samsung Developers site has getting started tutorial on Eclipse. Here in this post we will do the same setup in Android Studio.
1. First step is to create an android project in Android Studio
2. Copy LibAllShareInterface_2.0.0.jar file from AllShare Framework in your projects 'libs' folder. After that from the project Explorer window, right click on the file and click on 'Add as Library'
3. Add the follwing permissions to your manifest file:
4. Add the following in your main layout file.
5. MainActivity file:
AllShare can be used for the following purposes:
1. Sharing media files like videos, audios and photos. Media content can be streamed from the storage of the device or web server
2. Controlling smart devices like Smart TV,Smart Home Appliances remotely
3. Instant mirroring displays
AllShare framework is pre-installed in Samsung Galaxy S4, Samsung Home Sync, Samsung Galaxy S3, Samsung Note 10.1, Samsung Note 2, and Samsung Galaxy Camera Series. It will be pre-installed in all new Samsung devices.
That was about AllShare Framework. Now as a developer how do we get started ? Samsung Developers site has getting started tutorial on Eclipse. Here in this post we will do the same setup in Android Studio.
1. First step is to create an android project in Android Studio
2. Copy LibAllShareInterface_2.0.0.jar file from AllShare Framework in your projects 'libs' folder. After that from the project Explorer window, right click on the file and click on 'Add as Library'
3. Add the follwing permissions to your manifest file:
<uses-permission android:name="com.sec.android.permission.PERSONAL_MEDIA" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
4. Add the following in your main layout file.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:id="@+id/txtLog" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="==AllShare Device Discovery==" /> </LinearLayout>
5. MainActivity file:
import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.TextView; import com.sec.android.allshare.DeviceFinder; import com.sec.android.allshare.ERROR; import com.sec.android.allshare.ServiceConnector; import com.sec.android.allshare.ServiceProvider; import java.util.ArrayList; public class MainActivity extends Activity { private static String TAG = MainActivity.class.getSimpleName(); private final DeviceFinder.IDeviceFinderEventListener mDeviceDiscoveryListener = new DeviceFinder.IDeviceFinderEventListener() { @Override public void onDeviceAdded(com.sec.android.allshare.Device.DeviceType deviceType, com.sec.android.allshare.Device device, ERROR error) { mText.append("AVPlayer: " + device.getName() + " [ " + device.getIPAddress() + " ] " + " is added." + "\r\n"); } @Override public void onDeviceRemoved(com.sec.android.allshare.Device.DeviceType deviceType, com.sec.android.allshare.Device device, ERROR error) { mText.append("AVPlayer: " + device.getName() + " [ " + device.getIPAddress() + " ] " + " is removed." + "\r\n"); } }; ServiceProvider mServiceProvider = null; TextView mText = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mText = (TextView) findViewById(R.id.txtLog); mText.append("\n\n" + "Creating service provider!" + "\r\n\n"); ERROR err = ServiceConnector.createServiceProvider(this, new ServiceConnector.IServiceConnectEventListener() { @Override public void onCreated(ServiceProvider serviceProvider, ServiceConnector.ServiceState serviceState) { mServiceProvider = serviceProvider; showDeviceList(); } @Override public void onDeleted(ServiceProvider serviceProvider) { mServiceProvider = null; } }); if (err == ERROR.FRAMEWORK_NOT_INSTALLED) { // AllShare Framework Service is not installed. Log.d(TAG, "AllShare Framework Service is not installed."); } else if (err == ERROR.INVALID_ARGUMENT) { // Input argument is invalid. Check and try again Log.d(TAG, "Input argument is invalid. Check and try again."); } else { // Success on calling the function. Log.d(TAG, "Success on calling the function."); } } private void showDeviceList() { if (mServiceProvider == null) return; DeviceFinder mDeviceFinder = mServiceProvider.getDeviceFinder(); mDeviceFinder.setDeviceFinderEventListener(com.sec.android.allshare.Device.DeviceType.DEVICE_AVPLAYER, mDeviceDiscoveryListener); ArrayList<com.sec.android.allshare.Device> mDeviceList = mDeviceFinder.getDevices(com.sec.android.allshare.Device.DeviceDomain.LOCAL_NETWORK, com.sec.android.allshare.Device.DeviceType.DEVICE_AVPLAYER); if (mDeviceList != null) { for (int i = 0; i < mDeviceList.size(); i++) { mText.append("AVPlayer: " + mDeviceList.get(i).getName() + " [ " + mDeviceList.get(i).getIPAddress() + " ] " + " is found" + "\r\n"); } } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override protected void onDestroy() { if (mServiceProvider != null) ServiceConnector.deleteServiceProvider(mServiceProvider); super.onDestroy(); } }You can download the project from : https://github.com/opnchaudhary/AllShareFramework/archive/master.zip
Hi. Thank you so much for this write up. I am trying to connect my Samsung note 5 Verizon to my SMART tv but when I run the above code, ServiceConnector.createServiceProvider returns "FRAMEWORK NOT INSTALLED" error. When I checked in the /system/app, I dont see AllShareService.apk although I see other allshare apks. I tried to download the allshareservice apk version 1.0 from web but I am unable to install it on my device. According to the documentation, it says all phones s3 and above should have allshareservice. Is this code still relevant for the newer samsung devices? Thanks again!
ReplyDeleteHi. Thanks for the write up. I tried your code to connect my Samsung Note 5 Verizon to my SMART TV. however, ERROR err = ServiceConnector.createServiceProvider returns me an FRAMEWORK_NOT_INSTALLED error. I checked my device and I do not see any AllShareService.apk installed. But however I see other AllShare apks installed in it but not the AllshareService one. I got the allShareService apk somewhere from the web but I was not able to install it on my phone. Would your code work for note 5 or s6 onwards devices? If so, then do I need to have the AllShareService.apk installed on my device? Thanks in advance!
ReplyDelete