Encode/Decode any string using android base64 by using this setbaseEncode/setbaseDecode respectively. You can use this any of activity or separate class.
      public static String setbaseEncode(Context context,String str){  
           byte[] data = null;  
           try {  
                data = str.getBytes("UTF-8");  
           } catch (UnsupportedEncodingException e) {e.printStackTrace();}  
           String domainCode = Base64.encodeToString(data, Base64.DEFAULT);  
           return domainCode;  
      }  
      public static String setbaseDecode(Context context,String str){  
           byte[] data = Base64.decode(str, Base64.DEFAULT);  
           String decodestr = null;  
           try {  
                decodestr = new String(data, "UTF-8");  
           } catch (UnsupportedEncodingException e) {  
                e.printStackTrace();  
           }  
           return decodestr;  
      }  
 

 
 
 
0 comments:
Post a Comment