red orange yellow green blue

C2DM Setup Tutorial

May 2nd, 2012

I had to look around for some time to get all my questions answered when trying out C2DM the first time.  I hope that this answers most of the questions that you would have had!  I don’t cover the server side implementation of this, but I can give a brief overview of what to expect with it if needed.

 

1. First, you need to register over at Google’s signup page.

2.  Once you get a confirmation email back, and the server side is set up, you’re ready to go!

 

Notes

  • -ADMIN_EMAIL is the email address of the account you are publishing apps to the Play Store with.
  • -YOURACTIVITY is the your main Activity class.  If you make TestApp, then it would be TestApp.this
//Cloud to Device Messaging creation, receiving, and handling
//Creation done in onCreate unless you need it done elsewhere

//Must be done in a seperate thread due to networking
//Use AsyncTask once you know this works
new Thread(new Runnable()
{
    public void run()
    {
        Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
        registrationIntent.putExtra("app", PendingIntent.getBroadcast(YOURACTIVITY.this, 0, new Intent(), 0));
        registrationIntent.putExtra("sender", ADMIN_EMAIL);
        YOURACTIVITY.this.startService(registrationIntent);
    }
}
).start();

Next, you need a C2DM Receiver class that extends BroadcastReceiver


public class C2DMReceiver extends BroadcastReceiver {

@Override
public final void onReceive(Context context, Intent intent)
{
 if(intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION"))
 {
 handleRegistration(context, intent);
 }
 else if(intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE"))
 {
 handleReceive(context, intent);
 }
}

private void handleReceive(Context context, Intent intent)
{
 //This can change depending on what you get from your server
 //This shows how you can get a string from the Intent and create
 //a notification(not included)
 String payload = intent.getStringExtra("message");
 Log.d("C2DM", "Received Message: " + payload);
 createNotification(context, payload);
}

private void handleRegistration(Context context, Intent intent)
{
 String registration = intent.getStringExtra("registration_id");

 if(intent.getStringExtra("error") != null)
 {
 //You shouldn't get an error, but this will tell you what it is.
 Log.e(C2DMReceiver.class.getName(), intent.getStringExtra("error"));
 }
 else if(intent.getStringExtra("unregistered") != null)
 {
 //Unless you want to unregister the device, this shouldn't happen.
 Log.e(C2DMReceiver.class.getName(), "Unregister sent to device!");
 }
 else if(registration != null)
 {
 //Store the registration key. You have to send this to your server.
 SharedPreferences prefs = CCDirector.theApp.getPreferences(Activity.MODE_PRIVATE);

 prefs.edit().putString("registrationid", registration)
 .commit();
 }
 else
 {
 //Something happened, log the account and message
 String accountName = intent.getExtras().getString("account");
 String message = intent.getExtras().getString("message");

 if(message != null && accountName != null)
 {
 Log.d(C2DMReceiver.class.getName(), accountName + ": " + message);
 }
 }
}

} //end class

If everything has gone correctly, you should now be C2DM ready!

Bear with me!

April 29th, 2012

Unfortunately the site has had some code injected.  I am working hard on trying to find the issues.  I’m not too versed in websites and things like this so I’m hoping to have all of this solved soon.


Update: Switching website layout.  The old one may have been infected in the zip file.

 

Update #2:  It seems that the site is free of malware with the change of appearance and removal of some plugins.  I’ll be reworking the layout on some pages since they didn’t transfer over nicely from the previous layout.

 

Hectic year, time for an update!

April 24th, 2012

Many new and exciting things have happened since I last updated on the site.  I have moved down to Austin because the city has tons of job opportunities from full PC game programmer jobs to the new and booming mobile development, which I have been interested in and now I can’t get enough.  The next big thing that happened was that I got a job at Chances Media Entertainment.  This was a very small start up company with 1 iOS developer, 1 Android developer(me), 1 server/back-end engineer, 1 artist/web designer, a creative lead, and the head of the company.  Very demanding and rewarding experience.  Everyone usually pulled 9+ hour days because we all knew how much was needed to get the company up and running.  Unfortunately, the last big thing was that we all lost our jobs because of an investment issue that couldn’t be rectified.  It was a really hard day when they had to break the news to us.

 

 

The best thing to come out of working for the company was new friends and new knowledge.  We also published an app on the iTunes store and the Play Store.  Spot On Trivia was the game and I had a really good time working on it.

 

Also, the project that I worked on at Full Sail University is being feature in the MathAlive tour by the Smithsonian Institute!  It is currently in Washington D.C. and I’ve been told that the building is packed to the walls every day!  I’m really proud of the entire team and hope that it goes around the country long enough where I have the time and money to be able to see it for myself.

 

On a much sadder note,  my grandmother also passed away a few weeks after I was let go.  I’ve been looking on the brighter side of things though.  In her last months she was really happy and treated my mom much better than she did in previous years.  I know this made my mom really happy and I was glad that they had a good relationship before it was over.

 

Hopefully it won’t be another year before a new post!

Medal of Honor Stats App

January 21st, 2011

Today is the day, and this app has now gone live!

If you play Medal of Honor 2010 and are interested in your stats on the go, then this app is definitely for you. Simply type your name into the editbox and click update. Your stats will be retrieved using mohstats.com and can be saved to use on a widget.

I’ve read Friday is the best day for updates and publishing to the Android Market because traffic is higher so hopefully I get some hits today.

What did I learn in doing this? Well, I learned that JSON is an interesting thing and that it is frustrating and confusing at first. It was a good case of trial and error and error and trial until I worked through it enough to be able to understand how the data was stored. However, once I figured that out, it was pretty smooth sailing with retrieving all of the information needed for my app.

// get the content of our entity
InputStream is = entity.getContent();

// convert our stream to a readable string
String result = ConvertStreamToString(is);

// make a JSON object out of our string
StatsObj = new JSONObject(result);

// get the array from our names of the JSON object
StatsNameArray = StatsObj.names();

// get the values from our arrays
StatsValArray = StatsObj.toJSONArray(StatsNameArray);

// SPECIAL CASE:
// i need only a specific array from mohstats.com
JSONArray array1 = StatsValArray.getJSONArray(3);

// SPECIAL CASE:
// i only want the first object (the player information)
JSONObject new1 = array1.getJSONObject(0);

// from here on information gathering!
// specific strings are needed to get correct information
String ClanTag = new1.getString("clantag");

What else did I learn? Java and XML is a lot different than C++ and XML. You have to use data factories to get the necessary objects to be able to read and write data. It was an interesting time looking around to find out how to do this in Java and also helper functions are great for doing this as well.

    public void XMLoutSerialize(XmlSerializer ser, String namespace, String tag, String text)
    				throws IllegalArgumentException, IllegalStateException, IOException
    {
    	// simple function for one line tag, text, endtag functionality
    	ser.startTag(namespace, tag);
    	ser.text(text);
    	ser.endTag(namespace, tag);
    }

Android Apps!

January 12th, 2011

As I’m not too big of a blogger, I haven’t updated my website in too long of a time! Bad me! With a new update is new news. On the right of my website you can now see QR Codes that you can scan with your Android device using one of the many barcode scanners.

The current one is a simple tabbed soundboard application for the internet, and now Canadian TV, show Pure Pwnage. It takes the life of a pro gamer to all extremes and is one of the funniest shows I’ve watched. This app is a simple homage to the work they have done.

Next up on the app list is a Medal of Honor 2010 stats retriever with a widget so you can show your friends how good you really are. This should be done within the week and up on the market sometime next week. I will update again once it has been uploaded.

On the job front, still searching for that elusive first step into the business, but you can never give up.

Long time no post, now with XNA and Android experience

June 2nd, 2010

.
So it’s been roughly 3 months since I wrote anything here. Unfortunately I’m not the biggest blog poster in the world so things like this slip my mind.

In other news, currently working with four of my college friends on an XNA game that will hopefully be for download on Xbox in a month or two. The basic idea of the game is a vector graphics platformer, we haven’t seen one, so we decided to make one. You control a morphing object that can morph between certain shapes and use those to traverse the level. We’re currently working on getting networking down for multiplayer and the level editor complete with serialized objects.

Other than that, I’m currently working on a simple Android application to refresh on java and learn a new platform. It’s been done a ton of times, but a soundboard is a good starting application for phones. I’m hoping by the end of the week to have it finished. Only problem I’m currently facing is a long load time for the sound files. I’m sure the way I’m doing it isn’t the best and there are plenty of helpful places online for support for starting Android developers.

This is a very basic, not all inclusive look at what is going on. You have your main java file that extends TabActivity so your application can have multiple tabs. Then you use your Tab1 class to tell the intent, which is basically saying something is going to happen, to use the information in Tab1 and use setindicator to set the text on the tab and getdrawable to either use an image or refer to an xml file of what to draw. You then add this tab to the host of tabs.

public class MainJava extends TabActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       Resources res = getResources();
       TabHost tabHost = getTabHost();
       TabHost.TabSpec spec;
       Intent intent;

       // these three lines make a new tab
       intent = new Intent().setClass(this, Tab1.class);
       spec = tabHost.newTabSpec("tab1").setIndicator("Tab1",
    		   res.getDrawable(R.drawable.ic_tabimg)).setContent(intent);
       tabHost.addTab(spec);
}

public class Tab1 extends Activity
{
	Soundboard mSB;
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);

		// uses our nifty xml file
                // scrollview with linear layouts
		setContentView(R.layout.tab1);

                mSB = new Soundboard();
                mSB.InitSounds(getBaseContext());

                mSB.AddSounds(R.raw.soundname);

                Button SoundButton1 = (Button)findViewById(R.id.soundname);
                SoundButton1.setOnClickListener(new OnClickListener()
                {
			public void onClick(View v)
			{
				mSB.PlaySounds(1);
			}
		});
}

The days after moving back home….

February 14th, 2010

Well, I came back home on Sunday night at midnight in the aftermath of the blizzard that hit Pennsylvania, Maryland, Virginia, and Washington D.C.  I-95 at D.C. was a horrible mess and the only lanes available were the emergency lanes on the side of road.  The middle of the road was a sheet of ice that plows weren’t even making a dent in.

However, Monday was cold but nice, and on my way back home from a drive around town we encountered Pennsylvania deer, yes deer, in our development.

Then, Tuesday into Wednesday came and along with that came MORE SNOW!?!?!  If you look at the table you can see how much snow accumulated so far.

Now, there is supposed to be even more snow coming Monday and Tuesday.  Everyone up here is tired of snow and wondering where to put it when it snows again.

I have highlighters!

January 28th, 2010

A very simple get rectangle function for use with bitmap fonts.


RECT CBitmapFont::GetRect(int nIndex, int nCellW, int nCellH, int nCol)
{
 RECT rCell;

 rCell.left =   (nIndex % nCol) * nCellW;
 rCell.top =    (nIndex / nCol) * nCellH;
 rCell.right =  (long)(rCell.left + nCellW);
 rCell.bottom = (long)(rCell.top + nCellH);

 return rCell;
}

Coding can be fun, just use a keyboard!

January 24th, 2010

All i heard about when going into final project at Full Sail was that you were going to be burnt out on coding sometime during the five months. I didn’t experience this once. Personally, I would have rather been coding on my teams’ game seven days a week because on those off day Sundays I found myself quite bored. Maybe I’m just all around weird and can handle five month crunches like it’s just another day. Alas, the time of final project is 99% done, all that we have left is archiving so we can produce our game bible.

First! and Hello World!

January 22nd, 2010

Made by Holly Dorazio

Welcome everyone to the website of Andrew Castagno.  On this site you will find projects that I have had a hand in and maybe some code snippets as well.  The site is still under construction so bear with me as things are updated as quickly as I can.