January 2011 - Posts
With the latest MonoDroid Preview, the new logging functionality is:
Android.Util.Log.Debug("some identifier", "some message" );
Given that I have a cast on my arm, I installed the MonoDroid Development Framework for Apple Macs today. I walked through it and found that things are pretty much the same as with the MonoDroid plugin for Visual Studio 2010. This post shows the video displaying this. This video is based on MonoDroid Preview 11.1.
VIDEO
Subscribe to everything .
Subscribe to WMV .
Subscribe to M4V for iPhone/iPad .
Subscribe to MP3 .
Download WMV .
Download M4V .
Download MP4 .
Download MP3 .
I finally decided to test out the new MonoDroid on Mac preview. It
works, and it works almost exactly like MonoDroid on Visual Studio
2010. Here are some screen shots:
Creating a project.
Intellisense works when I try and create a new layout.
Starting the emulator
App running in the emulator on the Mac
And there you have it, it seems to be working.
One of the most annoying things when I build a desktop app in .NET is
MessageBox.Show() for displaying images or using a alert() in
Javascript is that I have to click on the popup dialog to make it go
away. I love the little messages at the bottom of an Android screen
that come up, display some text, and then go away. Its a Toast. Here's
a simple call to make one display.
Toast.MakeText(this, "some info goes here", ToastLength.Short).Show();
In my case, I wanted to report an error, so I did this:
catch (System.Exception e) { // log the error to the android logs. Android.Util.Log.D("MEDIA_PLAYER", e.Message); Toast.MakeText(this, e.Message, ToastLength.Short).Show(); }
I hope that this helps you out
So, I found a couple of issues in developing with MonoTouch that I need to be aware of. These are:
Spaces.
Don't have spaces in the project name. Spaces are bad. I've heard
that this is fixed with 3.2.4 of MonoTouch. Unfortunately, I tend to
think that I have lots of user errors. If you get an error about
a bundle identifier not being specified for the provisioning package,
or words along those line, you need to specify a bundle identifier.
This is done with this.
Sweet, I found out back in early December that an intro article that I
wrote regarding MonoDroid will be a "featured article" in Visual Studio
Magazine. I have no idea what "featured article" means, but hey it
sounds good. :-)
My next problem is going to be "How can I get 30
copies?" Seriously, I have no idea how to buy a bunch of copies. I'm
going to have to figure this out. Once subscription copy doesn't cut it
in my book.
Error logging, its such a simple concept. When an
error occurs, store some kind of information about the error. For some
reason, we don't seem to do lots of it. Why? Well, its usually fairly
easy to track down the information about an exception. With most web
apps, you can pretty much repeat the errors as you need to. Logging on
the server is fairly easy. Networks are fairly high speed and
dependable items of infrastructure. Is error logging really that
necessary?
Yes Virginia, error logging really is important. In
the mobile world, networks are not high speed or dependable. How do you
store information about those errors when the user is disconnected?
You can't just automagically write errors to the server log. What if
errors are occurring due to a bad network connection? How do I store
errors in a standard way? Well, I can't help you with everything, but I
can help you with storing errors on an Android Device with MonoDroid.
Storing error information with MonoDroid is actually
fairly easy. Android contains a set of Log.* methods to store data.
So, my strategy is basically a multi-step approach:
Store application information in Android with
Android.Util.Log.* methods. With these methods, you are writing to the
standard Android log. This will store errors in the standard locations
in android. Note that these are different from the MonoTouch methods
for storing errors. The MonoTouch method for this is Console.WriteLine.
If I am going to log errors in a running
application that will be released into the wild, storing the errors for
future removal is important. This can be stored in a SqLite database
table on the device.
Getting information from the device. To properly
get information from the device, we'll need to store this in a remote
database for further analysis. There needs to be a web service,
preferably a REST based service, for the device to communicate to and a
database that holds the data.
Hopefully, this helps you out with your data logging ideas.
Wally
The ability to program Android devices in C# using many of the libraries that you are already familiar with is rather cool. You may/not have heard about MonoDroid, which is an implementation of the Mono Framework, for Android. It has been in a closed beta. About 2 weeks ago, it became available in an open beta. While there are a number of things that it doesn't do at this point in time, you can tell that the Mono team is working towards getting many pieces working. If you are interested, check out the
MonoDroid web site .
I was working on some json/rest web services written in windows
communication foundation (wcf). I wanted to use the System.Json
namespace to do some of this. I made an http web request
asynchronously. In my call back method, I have following code doing a
linq query over this json result.
System.Json.JsonArray jsonArray = (System.Json.JsonArray)System.Json.JsonArray.Load(strm);
var twt = (from jsonTweet in jsonArray
select new Tweet
{
ProfileImage = jsonTweet["ProfileImage"].ToString(), Status = jsonTweet["Status"].ToString(), StatusDate = jsonTweet["StatusDate"], StatusId = Convert.ToInt64(jsonTweet["StatusId"].ToString()), UserName = jsonTweet["UserName"].ToString() }).ToList<Tweet>();
Now I have a list of type Tweet.
fyi, I didn't need to do a .ToList<> for this, but I was doing something else.
I hope this helps you out in your coding
I've got a WCF web service that exposes its data over REST. I'm
calling it from iPhone and Android. The method signature is something
like:
[WebInvoke(UriTemplate = "/UserValidate", Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] public bool UserValidate(string user, string pwd);
In the response, I've been getting something like this:
{ "UserValidateResult": { true } }
This
is crap as all I wanted is { true } or { false }. You can imagine that
when there was a bigger result coming back how this would complicate
things. I just want my basic data, nothing more or less. How the heck
do you get rid of the additional "UserValidateResult" junk. Well, now
we know. See that BodyStyle attribute on the interface? Change it to:
BodyStyle = WebMessageBodyStyle.WrapperRequest
Now, it seems to pass back what I need, which is { true / false }
PS. Hopefully, I didn't mangle this entry as its not been pulled 100% from my project. I can't just copy this code in.
PSS. Thanks to my buddy Nathan Blevins for pointing me in the right direction.
More Posts
Next page »