Welcome 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
package com.samsung.android.sdk.pen.pg.example1_1; import java.io.IOException; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Rect; import android.net.Uri; 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 import com.samsung.android.sdk.SsdkUnsupportedException; // Initializes and verifies that the S Pen is available import com.samsung.android.sdk.pen.Spen; // Allows you to manage SPD (S Pen Data Files) // Loads and saves SPD files // Adds and removes PageDocs from NoteDocs and attaches external files import com.samsung.android.sdk.pen.document.SpenNoteDoc; // Contains all the data and objects in a page // Adds, deletes, retrieves and changes layers, objects and general // settings for the page document. import com.samsung.android.sdk.pen.document.SpenPageDoc; // Allows for editing of the drawing surface with both a finger or the SPen import com.samsung.android.sdk.pen.engine.SpenSurfaceView; import com.samsung.spensdk3.example.R; 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; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_pen); 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 { spenPackage.initialize(this); // Is the SPen available for use isSpenFeatureEnabled = spenPackage.isFeatureEnabled(Spen.DEVICE_PEN); } catch (SsdkUnsupportedException e) { if( processUnsupportedException(e) == true) { return; } } 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.", Toast.LENGTH_SHORT).show(); e1.printStackTrace(); // Drop the Activity from memory finish(); } // Initialize the RelativeLayout in activity_hello_pen.xml RelativeLayout spenViewLayout = (RelativeLayout) findViewById(R.id.spenViewLayout); // 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.", Toast.LENGTH_SHORT).show(); finish(); } // Insert the drawing surface into the relative layout spenViewLayout.addView(mSpenSurfaceView); // 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 display.getRectSize(rect); 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.", Toast.LENGTH_SHORT).show(); e.printStackTrace(); finish(); } catch (Exception e) { e.printStackTrace(); finish(); } // Adds a page to the document mSpenPageDoc = mSpenNoteDoc.appendPage(); // Changes the background color mSpenPageDoc.setBackgroundColor(0xFFD6E6F5); // Clear undo / redo history mSpenPageDoc.clearHistory(); // 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 mSpenSurfaceView.setToolTypeAction(SpenSurfaceView.TOOL_FINGER, SpenSurfaceView.ACTION_STROKE); Toast.makeText(mContext, "Device does not support Spen. \n You can draw stroke by finger", Toast.LENGTH_SHORT).show(); } } // 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) { e.printStackTrace(); 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.", Toast.LENGTH_SHORT).show(); finish(); } // 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 dlg.setIcon(getResources().getDrawable( android.R.drawable.ic_dialog_alert)); // 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 .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override 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.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // Open Google Play and the Mobile SDK app startActivity(intent); // Close the dialog box dialog.dismiss(); finish(); } }) // If they hit the negative button .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog, int which) { // Check the value of closeActivity // that was sent to showAlertDialog if(closeActivity == true) { finish(); } // Close the dialog box dialog.dismiss(); } }) // If they hit the cancel button .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if(closeActivity == true) { finish(); } } }) // Display the dialog box .show(); dlg = null; } // The app is being shutdown and all resources will be lost @Override protected void onDestroy() { super.onDestroy(); // Close the SpenSurfaceView if(mSpenSurfaceView != null) { mSpenSurfaceView.close(); mSpenSurfaceView = null; } // Close the SpenNoteDoc if(mSpenNoteDoc != null) { try { mSpenNoteDoc.close(); } catch (Exception e) { e.printStackTrace(); } mSpenNoteDoc = null; } }; }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/spenViewLayout" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".PenSample1_1_HelloPen" > </RelativeLayout>
Information on my Contest
The Requirements for Entering the Samsung Smart App Challenge can be found here : http://developer.samsung.com/ssac2013/note/main.do
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 http://developer.samsung.com/signup 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!
i am new at this been wanting to learn i signed up for the samsung dev account also
Great, good luck in the contest
Just finished signing up for the site and i use your material and really really revere your wisdom!
Please do reply my email (sent to your youtube account)
You areeeeeeeeee AWEEEEEEEEEEESOMEEEEEEEEEEEEEEEEEE!!!
i signed up. nice vid 🙂
Thank you 🙂 Good luck
hey Derek i have already signed up and i’m up for a galaxy watch giveaway
I wish you the best of luck 🙂
Signed up for a developer account. Hopefully I can get somewhere in the app challenge. Keep up the good work!
Good luck in the App challenge. I’m happy to hear that you entered 🙂
Hi Derek, I signed up 🙂
Thank you 🙂 Good luck in the contest
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
Thank you 🙂 You very well may get your wish for the Galaxy Gear. I guess they are hard to find. I wish you the best of luck.
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.
Thank you very much for the compliment 🙂 Good luck in the contest
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
I’m very happy that I could help make what your teacher was covering easier to understand 🙂 Good luck in the contest.
Hey Derek, great collab with Samsung! just leaving my comment that I’ve signed up for a Samsung developer account.
Cheers!
Yes I hope this works out for them so i can give you guys more free stuff. It is very cool. Good luck in the contest.
Hi,
I have signed up for a developers account.
Great, you are entered in the contest 🙂 I wish you the best of luck.
Hallo Mr Banas,
I’ve already signed up for the Samsung Developer Account.
Thx i hope i can win the Item 😉
I wish you the best of luck 🙂
I have signed up for my Samsung Developer account and look forward to the rest of this series!
Great! I hope you enjoy it.
Hi!
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 🙂 .
I consider you to be entered in the contest. All you have to do is set up an account and leave a comment here so i know how to contact you. Good luck
I signed up!
Good luck 🙂
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!
Cheers!
You are in the running 🙂 Good luck
I signed up! Thanks for making these tutorials Mr. Banas.
You’re very welcome 🙂 Good luck
Hey there, I just signed up. Looking forward to future tutorials!
I wish you the best of luck
Thoroughly enjoying your tutorials, thank you very much!
Just signed up for the Samsung developer program.
Thank you 🙂 Good luck
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 😀
You have been entered in the contest. Good luck 🙂
Signed up! Thanks for all the great tutorials, keep them coming! 🙂
Thank you 🙂 Good luck in the contest
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
i singed up.
thx for the great tutorials btw!
Good luck in the contest 🙂
Hi Derek!
I have signed up for the samsung account.
Thank you so much for these wonderful tutorials 🙂
Cheers~
You’re very welcome 🙂 Good luck
I’ve signed up for the account. 🙂
Good luck 🙂
Hey Derek,
I have signed up =)
Thank you for your tutorials and making this competition happen!
You’re very welcome 🙂 Good luck in the contest
Thanks for your great tutorials. Very appreciated.
I just signed up for the Samsung Developer Account.
You’re very welcome 🙂 Watch my site at the end of the month I’ll announce the winners. Good luck
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 😉
Hey Pedro, I am very happy that I’ve been able to help. Good luck in the contest 🙂
Hi Derek
I signed up for the Developer Account.
Thanks and keep up the good work!
Hi Eric, Good luck in the contest 🙂 You’re very welcome.
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 🙂
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.
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.
Thanks!!
You’re very welcome. I’m very happy that I could help. Good luck in the contest 🙂
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!
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.
Hello Derek, Just signed up for a Samsung developer account and currently watching your tutorials. Hope to learn more of these! 😀
Hello Louie, Best of luck in the contest.
Derek, I have signed up for the Samsung developers account.
Thanks a lot to post all these learning videos for developers like me.
Good luck in the contest. You are very welcome 🙂
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!
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 🙂
Hello Derek, Just signed up for a Samsung developer account.
Good luck in the contest 🙂
I signed up. Thanks for the videos.
You’re very welcome 🙂 Good luck in the contest
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.
I’m very happy that you are enjoying the Android tutorials. Good luck in the contest 🙂
I have signed up 🙂
Good luck in the contest 🙂
hey Derek,
I made a samsung delvelopers acount. 🙂
Good luck in the contest 🙂
Hi Derek,
i made a Samsung developer account. love your videos 😉
Good luck in the contest 🙂
Hi Derek,
I made a Samsung developer account. Love your videos 😉
Thank you 🙂 Good luck in the contest
Hey Derek,
I have made a Samsung Account.
I love your vids!
Thanks,
Claire
Good luck in the contest 🙂
Hey Derek!
I have signed up with Samsung!
Thanks!!
Good luck in the contest 🙂
Yeah i also signed up………:)
Good luck 🙂
I signed up for the contest ..keeping my finger crossed 😀
Good luck 🙂
hi ,I made a Samsung account ..
It’s really easy to learn in less time through your android videos love it
Thank you 🙂
Hi Derek, I signed up.
I really admire what you do. Keep it up.
Thank you 🙂 Good luck in the contest.
I made a Samsung developer account.following your videos .and loving it
I’m happy to hear that 🙂 Good luck in the contest.
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 …
I’m very happy to hear that you are finding the videos useful 🙂 Good luck in the contest.
i have signed up in samsung developer account …learning java from your videos
Good luck 🙂
Hi there,
I just signed up for the competition at “samsung.com/sinup”
Regards
Good luck in the contest 🙂
Signed up for Samsung’s developers account. Love your tutorials, very clear and helpful.
Thank you 🙂 Good luck in the contest
Hey,
I made a samsung developers account. I realy like watching your videos and I would love to win one of the samsung devices.
-Chris
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 🙂
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.
Cheers
Karim
I signed up for a Samsung Developers account