published: November 3rd, 2009

Is GPS on? If not prompt user to turn it on.

Here’s a quick code snippet to determine if the GPS is on, and if it isn’t go to the Setting screen allowing the user to turn it on.  Android does not allow a 3rd party app to automatically turn the GPS on/off as of 1.5, a “feature” discussed extensively on the Android Developers Forum.

(more…)

published: October 22nd, 2009

AlertDialog for Android

Are you utilizing the full potential of AlertDialog?  I had no idea it was so versatile until I starting playing around with it recently.  I knew you could use it for a yes/no dialog for your mobile application, but I didn’t know it could also be an About dialog.  The API makes it really easy, although it doesn’t seem like the setPositiveButton() method is in the Android documentation.  The code snippet below cuts it down to the bare minimum.  It appears that a null can be passed instead of an empty OnClickListener and the action simply closes the window…which is the desired effect.

AlertDialog.Builder ad = new AlertDialog.Builder( this );
ad.setTitle( "About My Mobile Application" );
ad.setMessage( "This text explains My Mobile Application, thanks for " +
                       "purchasing it from the Android Market!" );
ad.setPositiveButton( "OK", null );
ad.show();

I’ve recently cleaned up a bunch of my code with this simple Dialog. And next I may have to look into the FrameLayout feature mentioned in the Android documentation.

published: October 11th, 2009

Email via Android Intent code snippet

I’m moving away from using the Android email client in Note To Me, but wanted to share the snippet to launch the client.  And who knows, maybe I’ll add it back in if people want it as an option.

        Button sendBtn = (Button) findViewById(R.id.send_btn_id);
        sendBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v)
            {
            	Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            	emailIntent.setType("text/html");
            	emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                  new String[]{ sendToAddress } );

            	emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject );
            	emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg );

            	hideKeyboard();

            	NoteToMe.this.startActivity(emailIntent);
            	NoteToMe.this.finish();
            }
        });