Wednesday, July 25, 2012

Use of variables in strings.xml in Android

e.g X company have Y employees
where X is a string variable and Y is an integer variable.

We can use this type of case in R.string also , as discussed below:

Write in strings.xml file
<string name="abc">%1$s company have %2$d employees.</string>
where $s stands for string
$d for integers

In java file
String mystring = getResources().getString(R.string.abc);
String finalstring = mystring.format(mystring, "Google",10000);

OUTPUT:
Google company have 10000 employees.

Sunday, July 22, 2012

Facebook and Twitter Sharing in Blackberry

With lot of research from last many months, finally i concluded a code for sharing status on facebook and twitter in Blackberry. So, make changes in attached code according to your need.
Please change application secret keys before executing it.


If any doubt and queries can comment below.


Download SharingKit

Tuesday, March 20, 2012

JSON Parsing in Android

try
        {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost postMethod = new HttpPost("Insert JSON Url");
            BufferedReader in = null;
            BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient.execute(postMethod);
            in = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
            StringBuffer sb = new StringBuffer("");
            String line = "";
            while ((line = in.readLine()) != null)
            {
                sb.append(line);
            }
            in.close();
            String result = sb.toString();

            JSONObject resObject=new JSONObject(result);
            String _key =resObject.getString("Insert Json Key");
            Vector _adBeanVector = new Vector();
            JSONArray newsArray = resObject.getJSONArray("Insert Json Array Key");
            if(newsArray.length() > 0)
           {
           for (int i=0;
            i < newsArray.length()
           ; i++)
           {
           Vector _adElementsVector=new Vector();
           JSONObject newsObj = newsArray.getJSONObject(i);
           _adElementsVector.addElement(newsObj.getString("Insert Json Array Element Key1"));
          _adElementsVector.addElement(newsObj.getString("Insert Json Array Element Key2"));
          _adBeanVector.addElement(_adElementsVector);
           }
           }
     }
 catch (Exception e)
{
}

Tuesday, January 24, 2012

JSON parsing in Blackberry

HttpConnection conn = null;
InputStream in = null;
String _response = null;
Vector _adBeanVector=null;
int code;
try
{
StringBuffer url=new StringBuffer().append(" Insert Json Url");
conn = (HttpConnection) Connector.open(url.toString(), Connector.READ);
conn.setRequestMethod(HttpConnection.GET);

code = conn.getResponseCode();
if (code == HttpConnection.HTTP_OK) {
in = conn.openInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[in.available()];
int len = 0;
while (-1 != (len = in.read(buffer))) {
out.write(buffer);
}
out.flush();
_response = new String(out.toByteArray());
JSONObject resObject=new JSONObject(_response);
String _key =resObject.getString("Insert Json Key");

_adBeanVector = new Vector();
JSONArray newsArray = resObject.getJSONArray("Insert Json Array Key");
if(newsArray.length() > 0)
{
for (int i=0 ;
i <  news Array.length()
 ; i++)
{
Vector _adElementsVector=new Vector();
JSONObject newsObj = newsArray.getJSONObject(i);
_adElementsVector.addElement(newsObj.getString("Insert Json Array Element Key1"));
_adElementsVector.addElement(newsObj.getString("Insert Json Array Element Key2"));
_adBeanVector.addElement(_adElementsVector);
}
}
if (out != null){
out.close();
}
if (in != null){
in.close();
}
if (conn != null){
conn.close();
}
}

} catch (Exception e)
{
Dialog.alert(e.getMessage());
}

Wednesday, November 2, 2011

Monday, October 17, 2011

Encode Image to BASE64 and Decode it- ANDROID (JAVA)

As of my Personal Experience, I am attaching a Base 64 file with my this post to convert Image to BASE64 and decode back. I have not written this Base 64 file but have taken a reference from other.


Download here

Thursday, September 29, 2011

To check number is odd or even without using OPERATOR( C++)

Hint: When we do conversion from decimal to binary then you have noticed that last digit of binary number is '0' if number is even ELSE '1'.
Using same logic we will solve this program.

#include "iostream.h"
#include "conio.h"
void main()
{
int number, last_digit;
cout<<"Enter the Number"; cin>>number;

last_digit=number & 1; //Give the last digit of Binary number

if(last_digit==0)
cout<<"Number is EVEN";

else
cout<<"Number is ODD";
}

Sunday, July 10, 2011

To change case of String

INPUT: JavA MaDe eASY

OUTPUT: jAVa mAdE Easy



class StringDemochangecase
{
static String changecase(String s)
{
String s1="";

for(int i=0;i {
char ch;
if(s.charAt(i)<91)
{
int c=s.charAt(i)+32;
ch=(char)c;
}
else
{
int c=s.charAt(i)-32;
ch=(char)c;
}
s1=s1+ch;
}
return s1;
}

public static void main(String args[])
{
String s="JavA MaDe eASY";
String s1=changecase(s);
System.out.println(s1);
}
}

Saturday, July 9, 2011

To check whether String is Palindrome or Not

public class StringDemopalindrome
{
static boolean palindrome(String s)
{
String s1="";
int i, flag=0;

for(i=s.length()-1;i>=0;i--)
{
s1=s1+s.charAt(i);
}

for(i=0;i {
if (s.charAt(i)!=s1.charAt(i))
flag =1;
}

if(flag==1)
return false;
else
return true;
}

public static void main(String args[])
{
String s="madam";
boolean b=palindrome(s);
System.out.println(b);
}
}

Calculate Length of String

public class StringDemolength
{
static int length(String s)
{
int i,count=0;
for(i=0;i {
count++;
}
return count;
}

public static void main(String args[])
{
String s="India is a good country";
int count=length(s);
System.out.println(count);
}
}