Monday, February 11, 2013

AIDL : Interaction between two apks in Android


You can understand it with one simple example of multiply two numbers , for this
I have made two projects name AIDLServiceProject and AIDLServiceClient.

In AIDLServiceProject, I have written core to multiply two numbers.

In AIDLServiceClient, I have passed two numbers to multiply.

IMultiplierService.aidl in projects will be common for both project for interaction and will be in same package name so that both AIDLServiceProject and AIDLServiceClient can interact each other.

For running the project , firstly run AIDLServiceProject so that service will start and after that run AIDLServiceClient.

Download the code

Friday, November 2, 2012

Mount Google Galaxy Nexus on Ubuntu 12.04(Precise)

1. Open Terminal
2. Run command "sudo apt-get install mtp-tools mtpfs gmtp"
3. Connect device to computer via USB
4. Select USB option to Media Device(MTP)
5. Enjoy, device mounted successfully.

Thursday, September 13, 2012

Facebook "Like" Button for iOS , Android and Blackberry



Before using this below code, please add facebook library to your project and use token of facebook Api to like facebook page.

public String likeFacebookButton( String urlWantToLike ) {

String url = null;

if(facebook.isSessionValid())
{
url = "http://www.facebook.com/plugins/like.php?" +
"href=" + URLEncoder.encode( urlWantToLike ) + "&" +
"send=false&"+
"layout=button_count&" +
"show_faces=false&" +
"width=100&" +
"height=21&"+
"action=like&" +
"font=arial&"+
"colorscheme=light&" +
"access_token=" + URLEncoder.encode( facebook.getAccessToken() );

}
return url;
}

Eclipse: "Run As","Debug As","Profile As" doesn't display the elements of list

Above problem have just wasted my whole day so i gone through all eclipse docs and community forums and finally i got the solution.

The solution to above problem is to execute this command in terminal

"sudo apt-get --reinstall install tzdata-java"

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);
}
}

Print String in Reverse Order

INPUT: INDIA

OUTPUT: AIDNI

public class StringDemoReverse
{
static String reverse(String s)
{
int i;
String s1="";
for(i=s.length()-1;i>=0;i--)
{
s1=s1+s.charAt(i);
}
return s1;
}

public static void main(String args[])
{
String s="India";
String s1=reverse(s);
System.out.println(s1);
}
}

Saturday, June 11, 2011

Swap Two Images on button click in JAVA

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class MyCanvas extends Canvas
{
Image i,j;
int flag;
MyCanvas()
{
Toolkit t= Toolkit.getDefaultToolkit();
i=t.getImage("f:\\hope.jpg"); //PATH OF FIRST IMAGE
j=t.getImage("f:\\Every_step.jpg"); //PATH OF SECOND IMAGE
}

public void paint(Graphics g)
{
if(flag==0)
{
g.drawImage(i,50,50,this);
g.drawImage(j,300,50,this);
}
if (flag==1)
{
g.drawImage(i,300,50,this);
g.drawImage(j,50,50,this);
}
}
}

class SwapImages implements ActionListener
{
MyCanvas m= new MyCanvas();
JFrame jf;
SwapImages()
{
jf=new JFrame("SWAP IMAGES");
jf.add(m);
JButton button1=new JButton("Swap");
Panel p=new Panel();
p.add(button1);
jf.add(p,BorderLayout.SOUTH);
button1.addActionListener(this);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(400,400);
jf.setVisible(true);
}

public void actionPerformed(ActionEvent e)
{
if(m.flag==0)
m.flag=1;
else
m.flag=0;
m.repaint();
}

public static void main(String s[])
{
new SwapImages();
}
}

Thursday, May 19, 2011

Swap two numbers without using third variable

Example:
Before Swap
number1=45 number2=33

After Swap
number1=33 number2=45



class Swap {
public static void main(String[] args) {
int number1=45,number2=33;
number1 = number1 + number2;
number2 = number1 - number2;
number1 = number1 - number2;
System.out.println("After swapping, number1= " + number1 + " and number2= "
+ number2);
}
}

Tuesday, May 17, 2011

Summation of elements of upper triangle of matrix

Example:
1 2 3
0 4 5
0 0 6
public class arraydemotriangleBsum {

static void triangleBsum(int x[][])
{
int i,j,c=0;
for(i=0;i<3;i++) { for(j=0;j<3;j++) { if(i>=j)
{
c=c+x[i][j];
}
}
}
System.out.println("The Sum of triangle B is:"+c);
}
public static void main(String[] args)
{
triangleBsum(new int[][]{{1,2,3},{4,5,6},{7,8,9}});
}

}

To find minimum number in upper triangle of matrix

Example:
1 2 3
0 4 5
0 0 6

public class arraydemotriangleBmin {

static void triangleBmin(int x[][])
{
int i,j,min=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{min=x[0][0];

if(i<=j)
{

if(x[i][j] {
min=x[i][j];
}
}
}
}
System.out.println("The Min Value in triangle B is:"+ min);
}
public static void main(String[] args)
{
triangleBmin(new int[][]{{1,2,3},{4,5,6},{7,8,9}});
}

}

To find maximum number in upper triangle of matrix

Example:
1 2 3
0 4 5
0 0 6

public class arraydemotriangleBmax {

static void triangleBmax(int x[][])
{
int i,j,max=0;
for(i=0;i<3;i++) { for(j=0;j<3;j++) {max=x[0][0]; if(i<=j) { if(x[i][j]>max)
{
max=x[i][j];
}
}
}
}
System.out.println("The Max Value in triangle B is:"+ max);
}
public static void main(String[] args)
{
triangleBmax(new int[][]{{1,2,3},{4,5,6},{7,8,9}});
}

}