Updates to the Facebook SDK 3.0 (Beta) for Android

SDK Version: 

Facebook recently announced a major update to the Facebook SDK for Android that makes it much simpler to manage login, publish to Open Graph, and measure the traffic you're getting from Facebook. The new SDK is also backwards compatible, so you can easily take advantage of new features like mobile app install ads without having to update a lot of code.

This article will walk you through the most important changes to the SDK, including:

1. Sessions and session management
2. Login view and fragment classes
3. API calls to Facebook
4. New native views for choosing friends or places
5. Mobile app install ads

Broadcast receiver Activity

SDK Version: 

If you want to catch a broadcasted intent on an Activity, you may get the following error:

  1. 02-22 08:18:46.874: E/AndroidRuntime(276): java.lang.RuntimeException: Unable to instantiate receiver com.helloandroid.broadcasttest.BroadcastTestActivity$MyBroadcastReceiver:
  2. ...
  3. java.lang.InstantiationException: com.helloandroid.broadcasttest.BroadcastTestActivity$MyBroadcastReceiver
  6. ...
  8. 02-22 08:18:46.874: E/AndroidRuntime(276): Caused by: java.lang.InstantiationException: com.helloandroid.broadcasttest.BroadcastTestActivity$MyBroadcastReceiver

Solving advanced animation problems

SDK Version: 

As we have seen in the previous animations tutorial it is easy to create some funny animations defined by XML.

Unfortunately in some cases we face troublesome limitations. Lest see them through an example:
We will create a simple animation that moves a buttom from the top left corner of the screen to the center when it is clicked, then remains there, and when clicked again it moves back to its original position

After you read the documentation it may seem easy to solve. We can define the animation realative to the parents size in percent (50%p), and the fillAfter attribute makes the button remain there, insted of jumping back to its original position. We can even define all of this in XML. So most of the problem seems to be solved with the few line of XML below:


Layar tutorial part 2

SDK Version: 

The first tutorial, we went through the steps to create a simple layer.
In this tutorial, we are going to explain how to include actions in this layer

Multitouch and gesture detection part 2

SDK Version: 

In my previous article I showed how to create a simple class that handles the basic gesture events such as ACTION_DOWN, ACTION_MOVE, ACTION_POINTER_DOWN, ACTION_POINTER_UP, ACTION_UP. Combinations of these, you can implement all of touch gesture stuffs thats you need in your work with a touch screen phone.

Handling multitouch
Create a boolean member variable in your MultitouchView class that stores the actual multitouch event. Name it isMultiTouch.

  1. public class MultitouchView extends View {
  2.         private boolean isMultiTouch = false;
  3.  {...}

Gallery intent tutorial

SDK Version: 

Our goal is to start the users gallery application, allow him to select an image, and use the chosen image in our application.

API Level 3 required!

We will start the operation on a buttons onclick event, implemented as follows:

  1. private static Bitmap Image = null;
  2. private static Bitmap rotateImage = null;
  3. private ImageView imageView;
  4. private static final int GALLERY = 1;

  1. public void onClick(View v) {
  2.   imageView.setImageBitmap(null);
  3.   if (Image != null)
  4.     Image.recycle();
  5.   Intent intent = new Intent();
  6.   intent.setType("image/*");
  7.   intent.setAction(Intent.ACTION_GET_CONTENT);
  8.   startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY);
  9. }

In order to avoid out of memory errors, we must recycle the previous image when the user presses the button second times or after that, so the returned bitmap is stored as a member variable, so we still have a reference for it when it is needs to be recycled.

RSA String Encryption, security

SDK Version: 

In this tutorial, I show you how to encrypt a string with public key in Android.

First we make a 2048-bit RSA private key in linux:

  1. $ openssl genrsa -out private_key.pem 2048

Then convert private Key to PKCS#8 format, what Java can read: (in Linux)

  1. $ openssl pkcs8 -topk8 -inform PEM -outform DER -in private_key.pem -out private_key.der -nocrypt

Advanced exception handling in Android

SDK Version: 

errorIn this tutorial I'll present you a simple exception handler class for Android. The class can invoke and display exceptions and it can be upgraded very easy for your further needs.

Custom views in a PreferenceActivity

SDK Version: 

Let's take another look at PreferenceAcitivites, and how we can use other views, than the basic PreferenceActivity views.

TabHost outside a TabActivity

SDK Version: 

I found no really easy to understand example on tabhosts, when you don't want to use a TabActivity, so here is one.

Syndicate content