Considering writing Android apps? Here’s what you need now

AndroidLogoNoTitleNow that I outlined what a developer needs to make iOS Apps, I thought I’d do the same thing for Android.

Q: What hardware do I need to develop for Android?

A: Unlike developing for iOS, someone can use almost any type of computer (Linux, Mac, Windows) that has the capability to have at least 1 Gigabyte of RAM.

Q: What about software?
A: Even though their are different environments to program for Android, I like programming in a Graphic Users Interface (GUI).  I recommend a program called Eclipse which you can download for free here.  But to make it even easier, Google has finally combined everything you need in one convenient archive.  For more information, click here.

Q: What language(s) do I need to learn?
A: First, since you use Java to write Android apps, learn that first without even thinking about developing for Android.  After that’s done, then you’ll learn how the Android Framework works, and what you have to do to combine the two languages in one.  It’s not easy, so take your time and most of all, have fun.

Q: Where can I go for books to learn?
A:  As with everything else, I use Amazon.com for all of my books and learning materials.  Just click here to get started.

Q: When I am ready to upload my app to the public, where do I go?
A:  Just go to http://developer.android.com.  They have all of the information you’ll need.

With these simple steps, you can be on your way to becoming an Android/Java programmer.

Java: Displaying the current date and time in the console

JavaLogoJava can be a bear to learn – especially if you’re trying to learn two languages at the same time (such as Android and Java).  But once you get the hang of it, it’s a really good starting language to learn.

One of the first things that I learned is to display the current date and time in the console.  Even though you may not use this in the “real world”, it did help me grasp the concept of how the language worked and how to format it so the computer could read it without showing me the dreaded error messages all the time.

Here’s the code:

import java.util.*;

class GetCurrentDateAndTime
{
   public static void main(String args[])
   {
      int day, month, year;
      int second, minute, hour;
      GregorianCalendar date = new GregorianCalendar();

      day = date.get(Calendar.DAY_OF_MONTH);
      month = date.get(Calendar.MONTH);
      year = date.get(Calendar.YEAR);

      second = date.get(Calendar.SECOND);
      minute = date.get(Calendar.MINUTE);
      hour = date.get(Calendar.HOUR);

      System.out.println("Current date is  "+day+"/"+(month+1)+"/"+year);
      System.out.println("Current time is  "+hour+" : "+minute+" : "+second);
   }
}	

As you can see by the above, it is really rather simple.

1.  You have to import the java interrupter into your program so the computer can read the code.
2.  You “initialize” the variables that you’re going to be using throughout the program.
3.  The programmer tells the computer what calendar they are going to use for the day, month, and year.
4.  Assign each variable to get today’s day, month, and year
5.  Assign another set of variables to get the current second, minute and hour
6.  Finally, print the results to the screen.

That’s it….Happy coding!

Android: How to use special characters

WarningIconThe other day, I was making a button with a label that had a minus sign (-) in it.  When I ran the program, I noticed that I was getting the warning icon (pictured on the right) when I ran the program either on a device or in the simulator.  After looking at the warning, it told me that I needed to use the Hex Code of the character that I wish to have inserted within the button’s label.

Having never done this, I had to learn how.  The below example is how to insert a special character on a button in Android:

<string name=”nameofstring”>This is how you put a minus sign – inside of a string</string>

Note:
Because of the fact that it is a Hex Code, this web site will not show the actual code necessary to display the minus sign.  Below is the way you would put it in the string, but without the spaces:

& 8 2 1 1 ;

You’ll have to find the Hex Code for each character you wish to have shown inside of a string.

That’s it.  Happy coding!

Android: How to center text Horizontally and Vertically

AndroidLogoNoTitleAndroid has a funny way when dealing with text.  Unlike iOS, you must tell Android how you want the text to show up if you want it to show other then at the left margin.

The below is all you need to:

1) Make text appear on the screen.
2) Center the text on the user’s screen.

In a post yesterday, I had you edit a file called string.xml.  In the below example, you will edit the file again and then do the rest of this exercise.

Make a new project and then name it TextExample.

Go to the res/values/ folder and double click on the strings.xml file.

Now type in the following just before the </resources> end tag:

<string name=”hi”>Hello this is a text example</string>

Save it and then double click the main.xml file.

Now, type the following:

<Textview
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:gravity=”center”
android:text=”@string/hi”
/>

Take note to the line android:gravity.  This is the line that will place your text either on the “left“, “center“, or “right“.

That’s it.  Happy coding!

You be the programmer!

HammerLogoWhen I started this web site, it was out of frustration of not finding any good coding examples for code that I needed to know quickly – especially with good-ol’ Android.

Now, it’s time for YOU to have a unique experience.  Over the next few days – or weeks – I am going to be posting code that may or may not have bugs in it.  The code may be for Android, iOS, or something else.  It is up to you to look at the code, copy it, run it, and then tell ME what’s wrong with it – if anything.

What do you get in return?  A chance to write an article about your findings that may be published on this web site for all to see.  The article must be on the topic that the code was written in.  How you found the error, what you did to fix it, and any hints and/or tips to get around the problem.  This is a unique opportunity to show others and the world what you’re made of.  If this unique opportunity takes off, your name may be included in a “top 100” programmers list that may appear on this web site later this year.

All challenges will begin with the subject Challenge followed by information of the challenge.  Then a small explanation will appear as to what the code is supposed to do, and then the code will follow.  Copy the code, run it, and see what happens.

This will begin in a few days – so get ready to show the world what you’re made of.  Good Luck!

 

Android: How to go from one screen to another and back again

AndroidLogoNoTitleLet me say from the start, that Android is a tough language to learn.  One not only has to learn the way Android works, but the person also has to learn and understand Java as well.  While that maybe fine for people who have the time to learn it, it sucks for people (like me) who have to learn it “on the fly” as I had to with a current customer who needed an app to be converted from iOS to Android.

Making single screen apps is fine.  But sooner or later, you’ll have to have an app where it has to go from one screen to another.  There are several ways to do this, but I’m going to show you one way that’ll get the job done (and keep your end users content at the same time).

The program will have one button on the main screen.  When the user taps it, it’ll go to the next screen with a “Back” button to go back to the previous screen.

Let’s call this example PageExample.  Make a new project in Eclipse and fill in the normal screens.

When that’s done, do the following:

– Find and then double click on the values folder and then find the strings.xml file, and then double click on that.

This file is where you define two things:

1) The name of a string that you’re going to “call” later in the app.
2) What ever you want the device to say to the user (you’ll see this in a minute).

You’ll input two of these strings.  One for the first button, and one for the second.

Now type the following:

<string name=”tapme”>Tap here to go to next page.</string>
<string name=”back””>Go Back</string>

The above should be easy to understand – especially if you’ve written in HTML at some point.

* The string name is the name of the value that you will use throughout the app when you want to show the message that follows it.  In this case, tapme.

* After that is the ‘human message’ that the user will see on the button itself.

* Finally, we “close out” the command with the </string> indicator.

Now save the file and then go in to the main.xml file – located in the /layout/ folder.

Open that file by double clicking it.

This is where you’ll define the first button that the end user will see.  Defining a button in Android is a little tough to get used to at first, especially if you’re used to iOS where you can visually make a button.

The file should look like this:

<?xml version=”1.0″ encoding=”utf-8″?>

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;

    android:layout_width=”fill_parent”

    android:layout_height=”fill_parent”

    android:orientation=”vertical” 

</LinearLayout>

We have to define the layout of the first screen that the user will see.  I am not going to go through each line of the above in this article.  You can learn more about it by going to http://developer.android.com.

Now, make room for the below command just before the </LinearLayout> command and type the following to build the first button that the user will see:

<!– Tap Me Button –>

<Button

    android:id=”@+id/tapbutton”

    android:layout_width=”fill_parent”

    android:layout_height=”wrap_content”

    android:text=”@string/tapme” >

</Button>

The above defines one button on the screen.

– The id is a button dentifier for the button that you’ll use later.

– The layout_width and layout_height are where you define the X and Y coordinates  of the button.  In this case, the layout_width will fill the entire length of the device.  The layout_height will make the button the height of the text that will show inside the button.

The android:text command calls the tapme string that you defined earlier and shows the text on the button.

Save the file.

Before we go any further, we have to create a new XML and JAVA file to go to when the user taps the Tap Me button.  We’re going to name it screen2.xml to keep things simple.

In Eclipse, click FILE > NEW > ANDROID XML FILE and name the file main2.xml.

Now, when you create a new XML file, you’ll need to also create a related Java file with the same name so the Android device can work with both files when it needs to.  These files are called CLASS files.

BUT you have to make sure that these files end up in the correct location of the file tree, or it may not work.

Click and then open the src folder as this is where you’ll put the Java (class) files.

Again, click FILE > NEW > CLASS FILES and name it main2

Now we have a problem.  We need to let the Android device know about the main2.xml file.  If not, the app may error out when they tap the first button.

Find and then open the AndroidManifest.xml file.  Don’t let this file scare you.  This is where you’ll define all of your other screens that the app may have.  Find the location where it says </activity>  Below that,  type in the following:

<activity android:name=”.main2″></activity>

An ACTIVITY is another activity that the app will do when a user taps the first button.

That’s done.  Now let’s do some coding.

We’ve defined the button earlier, now lets make it work.  Open the main.xml file and type the following after the following lines of code:

Button NEXT = (Button) findViewById(R.id.tapbutton);

        NEXT.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {

        Intent theIntent = new Intent(view.getContext(), Main2.class);

        startActivityForResult(theIntent, 0);

        }

        });

}

}

Now let’s take a look at what the code is doing:

1. We’ve define NEXT as the Android value for this button by activating it when the user taps the tap button value that we defined earlier.

2.  We then activate an onClickListener command so the device “listens” for a tap.

3.  We then make a new INTENT for another screen to appear after the tap (in this case, main2).

4.  Start the activity as soon as possible.

5.  Close out this block of code.

Now, open main2.java and type the following:

// Make the Back Button work:

Button back = (Button) findViewById(R.id.back);

back.setOnClickListener(new View.OnClickListener() {

public void onClick(View view) {

Intent intent = new Intent();

setResult(RESULT_OK, intent);

finish();

}

});

 }

}

Ok….This is where the magic happens when a user goes in to the main2.java file.  The button appears at the top of the screen and then (just like in main.java) it listens for the button tap.  When a user taps the button, it assigns a new Intent (more about Intents in a later article) and then the app will actually cause an error but you catch it by telling it the result of the error is OK and go back to the previous screen.  Finally, the device is finished with the code block so finish the block of code.

Whew!  That’s it….Happy coding!

News: Android 4.0 ported to Windows PCs and Tablets

(Cross Posted from: AndroidScoopNews):

AfterDawn – ”WindowsAndroid” has ported Android4.0 to Windows PCs and tablets, giving fans a chance to use the mobile operating system on their devices.

The full “Android experience” is available, including the browser, gallery, all Googlesoftware and even third-party apps. There is also graphics acceleration, a Dalvik VMand the standard Android user interface well known to Android users.WindowsAndroid works with touch, as well as keyboard and mouse so it should not matter where you install it.

On the third-party app side, even though the Google Play Store is available, most apps show up as incompatible. You can side load the files, but most cause WindowsAndroid to crash, at least at this early stage in its development.

iOS: Port iOS apps to BlackBerry 10

Guest post from Eun-Kyung Choi – Ed.

Why BlackBerry?

Over the past months, we’ve been showing you what the new BlackBerry 10 platform is all about and how easy it is to create rich and astonishing-looking apps for BlackBerry 10 using the Cascades UI framework. Not only does BlackBerry 10 offer an awesome platform and an extensive set of tools to choose from, butBlackBerry World is the most profitable mobile application store for app developers to submit their apps. According to the Evans Data Corporation, 13% of vendors using BlackBerry World are making over $100,000, which is more than Apple, Android and Windows Mobile. With BlackBerry 10, you have the option to integrate your application with BBM functionality, thus increasing the engagement and discoverability of your app. It is reported that BBM connected apps make up 20% of the app downloads from BlackBerry World. Also, the Built for BlackBerry Program and the $10K Developer Commitmentprograms are offering amazing incentives to bring your app to BlackBerry 10. I’d say that is a pretty convincing motivation to start developing apps on BlackBerry 10. So let’s get started!

To read the rest of the article, click here.

Android: How to do a basic Button

AndroidLogoNoTitleI’ve been programming in Android for some time now, and unlike other computer languages, it can be quite a challenge when it comes to:

1) Making a button
2) Getting them to do something when a user taps on one.

This article will cover 1), and then I’ll cover 2) at a later date.

Create a new project and call it ButtonExample.

We’re going to put one button on the user’s screen called Self Destruct.

Since we want the button to appear immediately after the user goes in the app, put the below in the main.xml file:

AndroidButtonExampleJPG

The above example should be easy enough:

1.  You’re telling Android that you’re starting to define  a button to be used later.
2.  The Height of the Button will be the height of the button’s text.
3.  The Width of the Button will be the width of a user’s device.
4.  The Text will show what ever text you assigned that variable in the string xml file (more on this at a later date).
5.  The button will then look for the name “selfDescruct” that you defined in the method block of the relating Java file.

That’s it …. Happy coding!

Android: How to install Android’s new developer’s tools

AndroidLogoNoTitleA few months ago, the Android community got a surprise when Google bundled its Android developer’s tools into one convenient downloadable file.  With a single download, the new developer can get the following:

  • Eclipse + ADT plugin
  • Android SDK Tools
  • Android Platform-tools
  • The latest Android platform
  • The latest Android system image for the emulator

If, however, you’re a current developer and wish to install pieces of the developer’s tools, you can do that as well.

This article will cover installing the above (because I believe “the easier the better!”)

Here’s what to do to get the whole package:

1.  Go to http://developer.android.com/sdk/index.html
2.  The web site should detect what operating system you’re using and send you to the correct version.
3.  Click the Download the SDK” button on the right.
4.  Wait for the download to complete.
5.  Unzip the ZIPped file (named adt-bundle<os_platform.zip) and move it to a location you’ll remember later ***
6.  Go to that location and execute the ECLIPSE application and follow the instructions on the rest of the set-up.
7.  That’s it.

*** Create a Folder called Developer and then do #5.  You’ll be able to keep track of where the development tools are easier.

After you go into Eclipse for the first time, it is a good practice to revise or download any SDK add-ons or tools so you can be sure your developing with the latest Android tools for your app.  To do this, go into Windows SDK Manager and follow the screens on how to update to the latest tools and resources.  These updates can take some time to download and install so make sure you have ample time to do this.  (Please see note marked with an “*”)

* It is not necessary if you’re just evaluating to see if Android is a platform that they wish to Develop for.

For further information on Eclipse and how to develop your first Android app, go to http://developer.android.com

Happy coding!