S Pen Remote SDK allows you to develop applications that use S Pen Remote generated events. S Pen includes buttons and motion sensor, and events from these units can be delivered to the application via the S Pen Framework. Simple gestures such as Button Click or 4-directional Swipe can be easily recognized via the S Pen Framework. But to implement a more powerful application using the raw data of units, you must use the S Pen Remote SDK.
Supported Platform
The package uses a static Java library that depends on internal Android framework modules. It means that this package only runs on devices that support those modules. Some Samsung Smart Devices do not support S Pen Remote as it requires devices of the Note series.
Supported Features
The S Pen Remote SDK provides functions to identify motion coordinates and verifying if the side button is pressed for your application.
S Pen Remote SDK supports the following detailed features:
Checking if the side button is pressed or released.
Identifying motion coordinates
two-dimensional device movement
relative values of the current position from the previous position
a positive value for the x-coordinates means to move right
a positive value for the y-coordinates means to move up
value range : -1.0 ~ 1.0
Components
Components
spenremote-v1.0.X.jar
sdk-v1.0.0.jar
Imported package:
com.samsung.android.sdk.penremote
Installing the SDK in Android Studio
To install SpenRemote in Android Studio:
a) Add the spenremote-v1.0.X.jar and sdk-v1.0.0.jar files to the libs folder in Android Studio.
b) Add dependencies for the SDK library folder in build.gradle
SpenRemote is a representative class and provides the following methods:
getInstance() gets the object of the SpenRemote. This class is singleton.
getVersionCode() gets the S Pen Remote version number as an integer.
getVersionName() gets the S Pen Remote version name as a string.
isFeatureEnabled(int type) checks if an S Pen Remote feature is available on the device.
connect() is used to connect to the S Pen Framework. You need to connect to the S Pen Framework to use S Pen Remote Features.
disconnect() is used to disconnect from the S Pen Framework.
The SpenRemote can run only on Samsung smart devices. Some Samsung smart device models do not support some of the features.
Check the Availability of SpenRemote Features
You can check if an SpenRemote feature is supported on the device using the isFeatureEnabled() method. The feature types are defined in the SpenRemote class. The feature type is passed as a parameter when calling the isFeatureEnabled() method. The method returns a boolean value that indicates the support for the feature on the device.
public boolean isFeatureEnabled(int type)
The following types are defined as constants in the SpenRemote class:
FEATURE_TYPE_BUTTON
FEATURE_TYPE_AIR_MOTION
Connecting to the S Pen Framework
Connect to the S Pen Framework to access the supported features in SpenRemote. To connect to The S Pen Framework, create a ConnectResultCallback and call the connect() method. If connection is already established, connect() method will not respond. Therefore, check the connection state with isConnected() method before attempting to connect.
SpenUnitManager mSpenUnitManager = null;
...
SpenRemote spenRemote = SpenRemote.getInstance();
if (!spenRemote.isConnected()) {
spenRemote.connect(getContext(),
new SpenRemote.ConnectionResultCallback() {
@Override
public void onSuccess(SpenUnitManager manager) {
mSpenUnitManager = manager;
...
}
@Override
public void onFailure(int error) {
}
});
}
If the connection is successful, ConnectResultCallback.onSucces() is called and a SpenUnitManager instance is passed. SpenUnitManager provides a method to set the Event Listener to monitor the events of embedded units in the S Pen.
If the connection fails, an error code is passed to ConnectResultCallback.onFailure(). The error codes that can be passed are as follows:
UNSUPPORTED_DEVICE: The device is not a Samsung device or S Pen Remote is not supported.
CONNECTION_FAILED: The S Pen Framework refuses the connection.
UNKNOWN: Unknown error.
Disconnecting
If your application is stopped or is no longer able to handle the S Pen Event, call disconnect() to terminate an established connection.
The SpenUnitManager provides a method to set the Event Listener to monitor the events of embedded units in the S Pen.
Related Classes and Interfaces
SpenUnit
This class manages instances of specific S Pen embedded unit.
SpenEvent
S Pen Framework will send this class to your application with S Pen event information.
SpenEventListener
You can use this interface to create a Callback method that can receive SpenEvent when an event occurs on an S Pen embedded unit.
Monitoring S Pen Events
To monitor S Pen events the following procedure is required
Get instance of SpenUnitManager
As introduced previously, the instance of SpenUnitManager can be obtained when a connection to the S Pen Framework is successful.
Request an instance of the embedded unit (SpenUnit) you want to monitor
To obtain instance of specific embedded unit, use getUnit method.
The getUnit method accepts a constant, TYPE_BUTTON or TYPE_AIR_MOTION, defined in the SpenUnit class as constants. If you try to obtain instance of unsupported unit in the device, it returns null.
// get Instance of Button Unit
SpenUnit button = mSpenUnitManager.getUnit(SpenUnit.TYPE_BUTTON);
// get Instance of AirMotion Unit
SpenUnit airMotion = mSpenUnitManager.getUnit(SpenUnit.TYPE_AIR_MOTION);
Register Event Listener
Register Event Listener to SpenUnit using registerSpenEventListener method of SPenUnitManager instance.
The data of SpenEvent passed to the SpenEventListener is hidden. You can refer to the data by casting it as a ButtonEvent or AirMotionEvent class, depending on the device you are monitoring.
Button Event :
SpenUnit button = mSpenUnitManager.getUnit(SpenUnit.TYPE_BUTTON);
mSpenUnitManager.registerSpenEventListener(mButtonEventListener, button);
...
//EventListener for Button Unit
private SpenEventListener mButtonEventListener = new SpenEventListener() {
@Override
public void onEventChanged(SpenEvent ev) {
ButtonEvent buttonEvent = new ButtonEvent(ev)
switch (buttonEvent.getAction()) {
case ButtonEvent.ACTION_DOWN:
Log.d(TAG, "Spen Button Pressed");
break;
case ButtonEvent.ACTION_UP:
Log.d(TAG, "Spen Button Released");
break;
}
}
};
Unregister Event Listener using unregisterSpenEventListener method of the SPenUnitManager instance, if your application is terminated or is no longer processing S Pen events. In particular, AirMotion consumes a large amount of S Pen battery power, so you should unregister the Event Listener when not handling Air Motion events.
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
.samsungdeveloperconference.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
LinkedIn
.ads.linkedin.com, .linkedin.com
Advertising Cookies
These cookies gather information about your browser habits. They remember that
you've visited our website and share this information with other organizations such
as advertisers.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Preferences Submitted
You have successfully updated your cookie preferences.