Samsung Mobile SDK Tutorial

Samsung Mobile SDK TutorialWelcome to my Samsung Mobile SDK Tutorial, which is part of my Android Development Tutorial. Over the course of this series I will take a look at many of the tools provided by the Samsung Mobile SDK while continuing to cover how to write code for Android in general.

I’m doing this series of tutorials because Samsung currently controls over 32% of the smart phone market (Apple controls 12% in comparison) and yet there are many more iOS tutorials then Samsung tutorials. I think that is a bit odd? I hope to solve that problem while also continuing to teach Android specific coding.

If you like videos like this it helps if you tell Google+ with a click here [googleplusone]

Don’t forget to check out the Samsung Smart App Challenge and if it is still November 2013, don’t forget to sign up to win a Samsung Galaxy Note 3, or Samsung Galaxy Gear Smart Watch on my site.

Code from the Video



import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.widget.RelativeLayout;
import android.widget.Toast;

// Used to make sure the device supports the Samsung Mobile SDK

// Initializes and verifies that the S Pen is available

// Allows you to manage SPD (S Pen Data Files)
// Loads and saves SPD files
// Adds and removes PageDocs from NoteDocs and attaches external files

// Contains all the data and objects in a page
// Adds, deletes, retrieves and changes layers, objects and general
// settings for the page document.

// Allows for editing of the drawing surface with both a finger or the SPen

public class PenSample1_1_HelloPen extends Activity {

	// A Context provides access to application resources
	// Launch activities, receiving Intents, managing sound,
	// Bluetooth management, modifying the clipboard,
	// requests downloads, interacting with input methods,
	// retrieve LayoutInflator, file creation, and retrieving a 
	// NfcManager, MsdManager for network service 
	// discovery, SearchManager, SensorManager, 
	// StorageManager, TelephonyManager, TextServicesManager,
	// UsbManager, Vibrator, WifiP2pManager (peer to peerWiFi),
	// WifiManager and WindowManager
    private Context mContext;
    private SpenNoteDoc mSpenNoteDoc;
    private SpenPageDoc mSpenPageDoc;
    private SpenSurfaceView mSpenSurfaceView;

    protected void onCreate(Bundle savedInstanceState) {
        mContext = this;

        boolean isSpenFeatureEnabled = false;
        // Create an SPen object
        Spen spenPackage = new Spen();
        // Try to initialize the Spen and if it doesn't exist
        // trigger an exception that is handled below
        try {
            // Is the SPen available for use
            isSpenFeatureEnabled = spenPackage.isFeatureEnabled(Spen.DEVICE_PEN);
        } catch (SsdkUnsupportedException e) {
            if( processUnsupportedException(e) == true) {
        } catch (Exception e1) {
        	// A Toast is a little message that opens in a gray
        	// box in the bottom of the screen
        	// Pass it the Context, message and how long to display
        	// the message
            Toast.makeText(mContext, "Cannot initialize Spen.",
            // Drop the Activity from memory

        // Initialize the RelativeLayout in activity_hello_pen.xml
        RelativeLayout spenViewLayout =
            (RelativeLayout) findViewById(;
        // Create the drawing surface on the device
        mSpenSurfaceView = new SpenSurfaceView(mContext);
        // Check if the SPen surface was created and if not display Toast
        // error message
        if (mSpenSurfaceView == null) {
            Toast.makeText(mContext, "Cannot create new SpenView.",
        // Insert the drawing surface into the relative layout

        // Display provides information on the display
        // Information about the size, density, orientation
        // refresh rate
        Display display = getWindowManager().getDefaultDisplay();
        // Holds 4 integer coordinates for a rectangle
        // bottom, left, right, top
        Rect rect = new Rect();
        // Get the size of the display as a Rect in pixels

        try {
        	// Create a SpenNoteDoc by passing the Context and the 
        	// width and height
            mSpenNoteDoc =
                new SpenNoteDoc(mContext, rect.width(), rect.height());
        } catch (IOException e) {
            Toast.makeText(mContext, "Cannot create new NoteDoc.",
        } catch (Exception e) {
        // Adds a page to the document
        mSpenPageDoc = mSpenNoteDoc.appendPage();
        // Changes the background color
        // Clear undo / redo history
        // Put the Spen document in the current view
        // and pass true to update the screen
        mSpenSurfaceView.setPageDoc(mSpenPageDoc, true);

        // Check if the Spen is available or not
        if(isSpenFeatureEnabled == false) {
        	// Set the type of tool to recognize as the finger
        	// and for the finger to be able to draw on the screen
                "Device does not support Spen. \n You can draw stroke by finger",

    // You get here if the device isn't a Samsung device, or
    // if the mobile SDK doesn't work with this device
    private boolean processUnsupportedException(SsdkUnsupportedException e) {
        int errType = e.getType();
        // Is this a Samsung device?
        if (errType == SsdkUnsupportedException.VENDOR_NOT_SUPPORTED
                || errType == SsdkUnsupportedException.DEVICE_NOT_SUPPORTED) {
            Toast.makeText(mContext, "This device does not support Spen.",
        // Is the SDK library installed?
        else if (errType == SsdkUnsupportedException.LIBRARY_NOT_INSTALLED) {

            showAlertDialog( "You need to install additional Spen software"
                +" to use this application."
                + "You will be taken to the installation screen."
                + "Restart this application after the software has been installed."
                , true);
        // If the SDK library is installed, but it is out of date
        else if (errType
                == SsdkUnsupportedException.LIBRARY_UPDATE_IS_REQUIRED) {

            showAlertDialog( "You need to update your Spen software "
                + "to use this application."
                + " You will be taken to the installation screen."
                + " Restart this application after the software has been updated."
                , true);
        // It is recommended, but not required that the user updates
        // the SDK library
        else if (errType
                == SsdkUnsupportedException.LIBRARY_UPDATE_IS_RECOMMENDED) {

            showAlertDialog( "We recommend that you update your Spen software" 
                +" before using this application."
                + " You will be taken to the installation screen."
                + " Restart this application after the software has been updated."
                , false);
            return false;
        return true;

    private void showAlertDialog(String msg, final boolean closeActivity) {

    	// Create a dialog box
        AlertDialog.Builder dlg = new AlertDialog.Builder(mContext);
        // Set the icon to display in the title
        // Use ic_dialog_alert which is a default Android icon
        // Change the title of the dialog
        dlg.setTitle("Upgrade Notification")
            .setMessage(msg) // Message to display in the dialog
            // Handle the event when the button is pressed
                new DialogInterface.OnClickListener() {
                    public void onClick(
                        DialogInterface dialog, int which) {
                    	// Create a Uniform Resource Identifier
                    	// to the missing software on Google Play
                        Uri uri = Uri.parse("market://details?id="
                                + Spen.SPEN_NATIVE_PACKAGE_NAME);
                        // Create an Intent which is an operation
                        // you will perform
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        // Set flags that define how the Intent is handled
                        // A new task is being started
                        // Close the current task / application before
                        // the new activity is started
                            | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        // Open Google Play and the Mobile SDK app

                        // Close the dialog box
                // If they hit the negative button
                new DialogInterface.OnClickListener() {
                    public void onClick(
                        DialogInterface dialog, int which) {
                    	// Check the value of closeActivity 
                    	// that was sent to showAlertDialog
                    	if(closeActivity == true) {

                    	// Close the dialog box
            // If they hit the cancel button
            .setOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    if(closeActivity == true) {

            // Display the dialog box
        dlg = null;
    // The app is being shutdown and all resources will be lost
    protected void onDestroy() {

        // Close the SpenSurfaceView
        if(mSpenSurfaceView != null) {
            mSpenSurfaceView = null;

        // Close the SpenNoteDoc
        if(mSpenNoteDoc != null) {
            try {
            } catch (Exception e) {
            mSpenNoteDoc = null;

<RelativeLayout xmlns:android=""
    tools:context=".PenSample1_1_HelloPen" >

Information on my Contest

The Requirements for Entering the Samsung Smart App Challenge can be found here :

I’m very excited to provide you with my Samsung Mobile SDK Tutorial! Over the next few videos I cover: the Samsung Mobile SDK.

Thanks to the nice people at Samsung and the Samsung Smart App Challenge, who are giving away $1.1 Million in prizes.

I’ll also be offering a give away. Between now and November the 30th, sign up for a free Samsung developer account at and you will be eligible to win a Samsung GALAXY Note 3 device or one of three Samsung GALAXY Gear smart watches. I will choose a winner at random.

After you signup for the Samsung developer account, leave a comment on my website stating that you signed up. That is all!

108 Responses to “Samsung Mobile SDK Tutorial”

  1. kisnon says:

    i am new at this been wanting to learn i signed up for the samsung dev account also

  2. Anonymous says:

    i signed up. nice vid πŸ™‚

  3. cjames says:

    hey Derek i have already signed up and i’m up for a galaxy watch giveaway

  4. Tomasz Kaminski says:

    Signed up for a developer account. Hopefully I can get somewhere in the app challenge. Keep up the good work!

  5. Azhar says:

    Hi Derek, I signed up πŸ™‚

  6. alvaro says:

    Great tut!… I already signed up for a samsung developer account, i wish i get the samsung gear since we don’t have those in Bolivia yet

  7. Henry says:

    I signed up for a developer account on samsung.
    I am learning to develop and your tuts really are a great help.
    Informative and quick, Best tutorials I’ve seen (I’ve seen quite a few. When I start making money I will definitely help support your efforts.

  8. Humayun Shimul says:

    I am taking a java beginner course in college and I was going to drop out of class but your java tutorials saved me. Thanks for all these amazing tutorials.Btw,I also signed up for the developer account:D

  9. Jerry says:

    Hey Derek, great collab with Samsung! just leaving my comment that I’ve signed up for a Samsung developer account.


  10. Raymond Lawson says:


    I have signed up for a developers account.

  11. Mohamad Rezky Anugerah says:

    Hallo Mr Banas,

    I’ve already signed up for the Samsung Developer Account.
    Thx i hope i can win the Item πŸ˜‰

  12. Michael Chadwick says:

    I have signed up for my Samsung Developer account and look forward to the rest of this series!

  13. arttu says:

    Apparently I already had a samsung account, but it throws an error while entering (not from password). Well I signed few years ago, so the long time has maybe caused it.
    But I don’t care that much if I’m not in competition for that reason. I just thought I’ll give a change for my luck πŸ™‚ .

  14. Joshua Nitin Gerard says:

    Hey Derek ! Thank you for your vids , i learnt a lot about android developing from them. I have signed up for a samsung developer account and hopefully ive qualified for your giveaway too!


  15. Kent Johnson says:

    I signed up! Thanks for making these tutorials Mr. Banas.

  16. Do Ju says:

    Hey there, I just signed up. Looking forward to future tutorials!

  17. iinteractive says:

    Thoroughly enjoying your tutorials, thank you very much!

    Just signed up for the Samsung developer program.

  18. Maciej Szpakowski says:

    Hi, Derek I just signed up for the Samsung developer account. I love your tutorials !!! I realy would like to win this awesome smartphone. I put this comment here also to be sure that I did everything fine πŸ˜€

  19. John Tell says:

    Signed up! Thanks for all the great tutorials, keep them coming! πŸ™‚

  20. Audrius says:

    Hello there,

    I have signed up for samsung developer account. Looking forward to start working with Samsung SDK, when I’ll get more free time

  21. AlfaXen says:

    i singed up.
    thx for the great tutorials btw!

  22. Andy Au says:

    Hi Derek!

    I have signed up for the samsung account.
    Thank you so much for these wonderful tutorials πŸ™‚


  23. Lily says:

    I’ve signed up for the account. πŸ™‚

  24. Ivan says:

    Hey Derek,

    I have signed up =)

    Thank you for your tutorials and making this competition happen!

  25. Luc Perron says:

    Thanks for your great tutorials. Very appreciated.

    I just signed up for the Samsung Developer Account.

  26. Pedro Poveda says:

    Hey Derek thanks for these great tutorials, they’re putting me ahead of the curve at college. And I also signed up for a Samsung Developer Account πŸ˜‰

  27. Eric Kim says:

    Hi Derek
    I signed up for the Developer Account.
    Thanks and keep up the good work!

  28. Parker says:

    Hi Derek !
    I just want to thank you ALOT for being the most helpful human on earth ! I’ve learnt many programming languages and watched the whole Java playlist .
    will be there some electronics stuff ? like Arduino maybe ?
    I’m very excited to see your future video tutorials ! what ever it will be .
    I signed succefully on samsung developer website.

    Thanks again πŸ™‚

    • Derek Banas says:

      Hi, Thank you very much πŸ™‚ I’m very happy that I was able to help. I definitely want to cover electronics since I have been doing a ton of work using custom made tools together with Android in the real world. I’ll hold a vote on the tutorial that will replace C soon.

  29. Kyle Brown says:

    I signed up for the Samsung developer. Just started watching your videos and i think their great! I’m probably going to use some of your tutorials to help me do my java final for school.

  30. Laurence Quinn says:

    I have signed up for a developer account.

    I’m currently working my way through Java but hope to start Android soon. I actually used my Java knowledge to write a nice program which dissects the HTML results file from an orienteering race and creates a text file with the chosen runners times compared to the best times (per kilometre and overall every kilometre etc.). It’s really nice to copy to a blog for a race report and has saved people interested a tonne of time as they used to write up a similar layout on their blogs manually!

    Thanks again!

    • Derek Banas says:

      That sounds very cool! Yes, I automate just about everything in my life. Once you combine electronics with programming it is very easy to automate most everything. I few months back it made me laugh when a door to door salesman tried to sell me a security system. I asked him into my house and showed him the one I built. I didn’t build it to protect anything because I don’t really have anything. It was just a fun thing to do πŸ™‚

      Best of luck in the contest.

  31. Louie says:

    Hello Derek, Just signed up for a Samsung developer account and currently watching your tutorials. Hope to learn more of these! πŸ˜€

  32. vfunbox says:

    Derek, I have signed up for the Samsung developers account.
    Thanks a lot to post all these learning videos for developers like me.

  33. Keith says:

    Hey derek, I’ve been going through your tutorials lately and they’ve helpedme learn several new things. I was also going through some topics I already knew (like your html and css tutorials), and even those were refreshing.

    I look forward to your samsung series, I’ve got an old galaxy s captivate I used for starting android development and my daily carry for the last few years has been a galaxy nexus. Ironically I’ve never looked twice at samsung development so I’ll be following you through this. I’ve registered on samsungs developer website in hopes of nabbing some contest prizes or maybe a gn3. Either way this is a push in the right direction for me, I applied for the tegra development kit a while back and sort of gave up on OEM specific development when they never contacted me back. Thanks and keep up the good work!

    • Derek Banas says:

      Hey Keith, Yes it has been fun to cover a brand new SDK right out of the oven. I’ve never done that before. It has been fun to be the guy that explored this API pretty much for the first time. I hope you guys have enjoyed the ride as well πŸ™‚

  34. Imran Ali says:

    Hello Derek, Just signed up for a Samsung developer account.

  35. Andrew says:

    I signed up. Thanks for the videos.

  36. Manley says:

    Hey Derek!

    I signed up for the Samsung account πŸ™‚

    Also thanks a ton for your Android series! Sooooooo awesome :D. This new series is looking great too! Thanks for giving your time to help me learn.

  37. Fredrik Westman says:

    I have signed up πŸ™‚

  38. Roald says:

    hey Derek,

    I made a samsung delvelopers acount. πŸ™‚

  39. Roald says:

    Hi Derek,

    i made a Samsung developer account. love your videos πŸ˜‰

  40. Roald says:

    Hi Derek,

    I made a Samsung developer account. Love your videos πŸ˜‰

  41. Claire says:

    Hey Derek,

    I have made a Samsung Account.

    I love your vids!


  42. Zak says:

    Hey Derek!

    I have signed up with Samsung!


  43. Mohd Ali says:

    Yeah i also signed up………:)

  44. Mehboobhi says:

    I signed up for the contest ..keeping my finger crossed πŸ˜€

  45. Mohammad Ali says:

    hi ,I made a Samsung account ..
    It’s really easy to learn in less time through your android videos love it

  46. Esteban says:

    Hi Derek, I signed up.
    I really admire what you do. Keep it up.

  47. Mohd Ali says:

    I made a Samsung developer account.following your videos .and loving it

  48. Mohammad Ali says:

    signed up in samsung developer account …downloaded your videos …made a pdf of your code for reference ..lots of knowledge in less time love it …

  49. Shehnaz says:

    i have signed up in samsung developer account …learning java from your videos

  50. Le says:

    Hi there,

    I just signed up for the competition at “”


  51. Robert Waite says:

    Signed up for Samsung’s developers account. Love your tutorials, very clear and helpful.

  52. Chris Geurts says:


    I made a samsung developers account. I realy like watching your videos and I would love to win one of the samsung devices.


    • Derek Banas says:

      Hey Chris, The phone has been claimed, but the 3 smart watches still haven’t. If they aren’t claimed by next Friday I’ll hold another drawing to pick new winners. Good luck πŸ™‚

  53. Karim Benabd says:

    I am in Derek!!
    I hope I will get the Note III.
    I writing this from a Note II πŸ™‚
    Thank you very much d’or everything you are doing for us here.

  54. Scott says:

    I signed up for a Samsung Developers account

Leave a Reply to Roald Cancel reply

Your email address will not be published.