JDBC and MySQL

 

import java.util.logging.Level; import java.util.logging.Logger;

// import com.mysql.jdbc.*; import java.sql.*;

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author sukanta */ public class Main {

    public static void main(String[] args) throws SQLException {         try {             Class.forName("com.mysql.jdbc.Driver");         } [...]

Download a forex quote

 

import java.net.*; import java.io.*;

public class ForexTest {     public void getRate() {         try {             URL url = new URL("http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s=EURUSD=X");             URLConnection urlc = url.openConnection();

            BufferedReader reader = new BufferedReader(new InputStreamReader(urlc.getInputStream()));

            String line;             StringBuffer sb = new StringBuffer();

            while ((line = reader.readLine()) != null) {                 sb.append(line);             [...]

Download a web page

 

import java.io.BufferedInputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection;

/** * Main.java * * @author www.javadb.com */ public class Main {         /**      * Reads a web page into a StringBuilder object      * and prints it out to console along with the      * size of the page.      */ [...]

Open a url in browser

 

Intent viewIntent = new Intent("android.intent.action.VIEW",Uri.parse("http://java.codentuts.com"));  startActivity(viewIntent);

Start a phone call

 

try {    Intent intent = new Intent(Intent.ACTION_CALL);    intent.setData(Uri.parse("tel:+123456"));    startActivity(intent); } catch (Exception e) {    Log.e("SampleApp", "Failed to invoke call", e); }

Identify an android device

 

import android.provider.Settings.Secure;    private String android_id = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);