New Developer Features for the Galaxy Note9 S Pen

Tony Morelan

Senior Developer Evangelist

With the launch of the new Samsung Galaxy Note9 comes all new features for the S Pen. Developers now have the ability to utilize the new BLE (Bluetooth Low Energy) remote technology connection. From a distance, users are able to control app features with either a single or double press of the S Pen button.

Using the S Pen as a shutter remote, users can now control the Note9 camera from a distance. Just point, pose and take your photo from anywhere.

You can also control your media with the S Pen. Play, pause and advance your presentation slides, pause movies and skip songs, all with the press of a button.

With its fine 0.7mm tip and 4096 levels of pressure, the S Pen has precise control and responsiveness. Visit the Samsung Developer Website to learn more about the S Pen, the Bluetooth Low Energy technology, and the S Pen framework.

Sample App: S Pen Remote

Download the new S Pen Sample App and see how you can take advantage of these new features.

Sample Code: Implementation of RemoteActions

Specifying the KeyEvent to be Mapped to the S Pen Remote Event in a Manifest

  1. Check for the activity to handle the KeyEvent in a manifest file (AndroidManifest.xml).
  2. Add <intent-filter> and <meta-data> elements to that activity. An .xml resource file defining RemoteActions must be specified for <meta-data>.

<manifest xmlns:android="http://schemas.android.com/apk/res/android> package="com.samsung.android.blesample "> <application ... > <activity android:name="SampleActivity" > <intent-filter> <action android:name="com.samsung.android.support.REMOTE_ACTION" /> </intent-filter> <meta-data android:name="com.samsung.android.support.REMOTE_ACTION"                             android:resource="@xml/remote_action_sample"/> </activity> ... </application> </manifest>

_*_Only 1 RemoteAction per app is allowed at the moment. If you define RemoteActions to several activities, all other except one may be ignored.

  1. Create an .xml file under res/xml/. (Name the file with the same name as the resource specified in Step 2.)

XML has a root element of , and may include several elements. In addition, each contains information about id, label, priority, trigger_key, etc.

<?xml version="1.0" encoding="utf-8"?> <remote-actions version="1.0"> <action id="page_down" label="@string/page_down" priority="1" trigger_key=" PAGE_DOWN "> </action> <action id="page_up" label="@string/ page_up" priority="2" trigger_key="PAGE_UP"> </action> <action id="right" label="@string/start_activity" priority="3" trigger_key="CTRL+LEFT+N "> </action> </remote-actions>

element

element

Implementation of KeyEvent-Callback

Implement the KeyEvent-Callback to the activity to which the RemoteActions have been declared. Since it is the same as handling an Android KeyEvent, only the simple examples of the implementation are introduced here.

Please refer to the Android developers website for detailed guidelines.

It is recommended to handle the sent KeyEvent at onKeyDown.

Example :

  • Page Down key: Scroll ScrollView as much as +500 in Y direction.
  • Page Up key: Scroll ScrollView as much as -500 in Y direction.
  • Ctrl + N: Open SampleActivity2.

`public class SampleActivity extends Activity {
private ScrollView mScrollView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sample_activity1_layout);
mScrollView = (ScrollView) findViewById(R.id.scroll_view);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_PAGE_DOWN) {
mScrollView.smoothScrollBy(0, 500);
} else if (keyCode == KeyEvent.KEYCODE_PAGE_UP) {
mScrollView.smoothScrollBy(0, -500);
} else if ((event.getMetaState() & KeyEvent.META_CTRL_ON) != 0
&& keyCode == KeyEvent.KEYCODE_N) {
Intent intent = new Intent(this, SampleActivity2.class);
startActivity(intent);
}
...
return super.onKeyDown(keyCode, event);
}
}`

*Pay attention to cases when the child view consumes the KeyEvent.

For example, if the EditText is focused on a screen where the EditText co-exists, most KeyEvents will be consumed for text inputs or a cursor movement and they may not be sent to the Activities or Container Layouts.

On this screen, you must specify the key code or key combination that the child view cannot consume.

Learn more about developing for the S Pen at this year's Samsung Developer Conference.

Preferences Submitted

You have successfully updated your cookie preferences.