AddHead(new Html(<< tt {font-size:9pt} EOD )); $page->AddPost(new Post('What is an Intent', <<Intent. Read the Class Overview of the Intent Documentation. Ignore any parts that don't make sense to you - just try to get the big picture of what an Intent is. EOD )); $page->AddPost(new Post('Intending to view a web page', <<The following code snippet will request a web page to be viewed: (you will need to add import android.content.Intent; and import android.net.Uri; to the top of your java file to use this)

	Intent intent = new Intent(Intent.ACTION_VIEW);
	intent.setData(Uri.parse("http://www.google.com"));
	startActivity(intent);

Try adding this code to the app you were using for the first tutorial, or try to make a new project for this code. Try to make it so the code executes when you push a button.

EOD )); $page->AddPost(new Post('What else can I intend to do...', <<If opening a web page is not your thing, how about:

  • Viewing your contacts: replace http://www.google.com with content://contacts/people.
  • Bringing up a number to call: replace http://www.google.com with tel:(555)555-1234. You can also replace Intent.ACTION_VIEW with Intent.ACTION_DIAL (will work the same).
  • For a list of things you can do if you have the right applications installed (you probably don't on your emulator), see this list. For example, on an actual phone you can very easily send an e-mail using an intent, but on the emulator none of the apps know how to process the request.
EOD )); $page->AddPost(new Post('I want to initiate a call', <<The previous section showed you how to bring up a number to be called. The user then has to hit the green call button to actually initiate the call. But what if you wanted to initiate a call from your app, without any user intervention?

Let's try to do that (we won't succeed at first, so expect failure). From the original code snippet, replace http://www.google.com with tel:(555)555-1234 and replace Intent.ACTION_VIEW with Intent.ACTION_CALL. Try running the app. When you execute the calling code, you will get an error that says something like "Sorry! The application Hello World (process com.urbanstew.HelloWorld) has stopped unexpectedly. Please try again".

The problem was that the app did not have permission to initiate calls. If you are feeling adventurous and want to learn a little about debugging, go into you operating system's terminal window and enter adb logcat. You will get a long output, and somewhere close to the bottom you will see:

E/AndroidRuntime( 1194): java.lang.SecurityException: Permission Denial: starting Intent { action=android.intent.action.CALL data=tel:(555)555-1234 comp={com.android.phone/com.android.phone.OutgoingCallBroadcaster} } from ProcessRecord{43741e48 1194:com.urbanstew.HelloWorld/10018} (pid=1194, uid=10018) requires android.permission.CALL_PHONE

This friendly error message tells you about the lack of permission to call.

To avoid this error, we need to give the app permission to initiate calls.

After you give the permission, try running the app.

EOD )); $page->AddPost(new Post('Next steps', <<Unfortunately, the emulator doesn't have a whole lot of apps installed that can process intents. For an overview of things you could do on the phone, you can take a look at the beginning of this brief tutorial.

EOD )); $page->AddPost(new Post('Back to tutorial page', <<When you're done with this, you can move on to another tutorial.

EOD )); $page->Render(); ?>