Tuesday 27 March 2012

System Services and BroadcastReceiver with Alarm Demo in Android







AlaramActivity.java



MyBroadcastReceiver.java


AndroidManifest.xml

Note : Keep in mind that the vibrator alarm does not work on the Android emulator.
  • Add to  receiver in AndroidManifest.xml

Sunday 18 March 2012

Email Validation in Android



Email_ValidationActivity.java
package com.Email_Validation;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class Email_ValidationActivity extends Activity {

    EditText TextEmail;
    String emailString;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextEmail = (EditText) findViewById(R.id.txtEmail);
    }

    String regEx = "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" + "\\@"
            + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" + "(" + "\\."
            + "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" + ")+";

    public void btnValidateEmailAddress(View v) {
        emailString = TextEmail.getText().toString().trim();

        Matcher matcherObj = Pattern.compile(regEx).matcher(emailString);

        if (matcherObj.matches()) {
            //Toast.makeText(v.getContext(), emailString + " is valid",Toast.LENGTH_SHORT).show();
            showAlert(emailString + " is valid", v.getContext());
        } else {
            //Toast.makeText(v.getContext(), emailString + " is InValid",Toast.LENGTH_SHORT).show();
            showAlert(emailString + " is InValid", v.getContext());
        }
    }
   
    // For alert message

        public static void showAlert(String msg, Context context) {
            AlertDialog.Builder builder = new AlertDialog.Builder(context);
            builder.setMessage(msg).setPositiveButton("Ok", dialogClickListener)
                    .show();
        }

        static DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                    // Yes button clicked

                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    // No button clicked
                    break;
                }
            }
        };

}


Layout : main.xml

Friday 16 March 2012

Show Error Message in EditText - Android


Note : If user can not enter any messages in edittext and press click button then next screen will display with error message. 

Show_ErrorActivity.java



Layout:main.xml




WebView in Android


Web_ViewActivity.java


Layout : main.xml


AndroidManifest.xml


Wednesday 14 March 2012

Share Application with another Android phone

First you click share button next screen will display.


You can share your application like this. 






ShareApplicationActivity.java



Layout : main.xml


AndroidManifest.xml
    


 Note : How to gave perminssion in android.
  1. First of all you go to AndroidManifest.xml file in your application.
  2. Goto permission tab menu.
  3. Click Add button and another window open click on Uses Permission then press ok.
  4. Select to android.permission.INTERNET.



Rounded or Circle ImageView with Shadow in Android

RoundedImageViewShadow.java public class RoundedImageViewShadow extends ImageView {     private static final ScaleType SCALE_TYPE ...