Posts

Showing posts from July, 2017

Internet connection check in android

  Every Service related app we need to check network available in phone or not before call any web service. The source code is given bellow. import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class CheckNetworkConnection {     public static int TYPE_WIFI = 1;     public static int TYPE_MOBILE = 2;     public static int TYPE_NOT_CONNECTED = 0;     public static int getConnectivityStatus(Context context) {         ConnectivityManager cm = (ConnectivityManager) context                 .getSystemService(Context.CONNECTIVITY_SERVICE);         NetworkInfo activeNetwork = cm.getActiveNetworkInfo();         if (null != activeNetwork) {             if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)                 return TYPE_WIFI;                         if(activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)                 return TYPE_MOBILE;         }         retur

Email Id Validation in android

Email id validation in front end in app is very common things in android  . Here is the code to check email id in android . import java.util.regex.Matcher; import java.util.regex.Pattern; public class EmailValidator { private Pattern pattern; private Matcher matcher; private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; public EmailValidator() { pattern = Pattern.compile(EMAIL_PATTERN); } public boolean validate(final String hex) { matcher = pattern.matcher(hex); return matcher.matches();   } } // for  activity  if(new EmailValidator().validate(etEmail.getText().toString())==false) {    // write code for not valid } else {   // write code for valid } Find Us :          Facebook : @apnaandroid         Google+   : Apna Java         Youtube : Android & Java

Pan Number Format validation in Android Or Java

For PAN No. format validation in Java we need to write this simple code in Java class. Hope this class will help you a lot. 1.   First create a class called  PanValidator . import java.util.regex.Matcher; import java.util.regex.Pattern; public class PanValidator {     public boolean isValidPan(String pan) {         Pattern mPattern = Pattern.compile("[A-Z]{5}[0-9]{4}[A-Z]{1}");         Matcher mMatcher = mPattern.matcher(pan);         return mMatcher.matches();     } } 2.   Call is call from Activity or fragment in android   :          boolean isValidPanNo= new PanValidator().isValidPan(String strYourPanNo);    if( isValidPanNo)    {           // write your logic      }else{         // write your logic } 3.   Call this class from java class ::         Class A{           public static void main(String args[])             {                PanValidator pv=new PanValidator();                 System.out.println

Custom Calendar in android

Image
Custom calendar is very important part in android . Using custom calendar we can easily customize calendar activity as per our requirements . I am describing how to create a custom calendar in android  . Its very easy to integrate in eclipse as well as studio. I hope it will help you a lot . For create a custom calendar you have to follow these bellow steps . The steps are 1.   Create a shape file  " circile_cyan.xml " in your drawable folder .        <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="oval" >     <solid android:color="#00FFFF" >     </solid> </shape> 2.   Create a shape file  " circile_grey.xml " in your drawable folder . <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"