Monthly Archives: April 2011

9,408 views

TTS text to speech Android example

Android development example source code // import import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech.OnInitListener; // you have to add implementation public class Main extends Activity implements TextToSpeech.OnInitListener { private int _langTTSavailable = -1; // set up in onInit method // declaration private TextToSpeech … Continue reading

Posted in Android Examples Code | Tagged , , , , | Comments Off on TTS text to speech Android example
6,386 views

Number convert int to string Java Android example code

Convert number int to string Android Java example source code. int n = 0;   try { n = Integer.parseInt("21")); } catch(NumberFormatException e) { System.out.println("Could not parse " + e); } // int to string String s = String.valueOf(24);

Posted in Android Examples Code, Array,List,Collections | Tagged , , , | Comments Off on Number convert int to string Java Android example code
2,416 views

Screen Android Landscape Portrait programmatically

Screen Android example source code for developers. Get orientation of screen. public int getScreenOrientation() { if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { return 1; // Portrait Mode   }else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { return 2; // Landscape mode } return 0; … Continue reading

Posted in Android Examples Code | Tagged , , , , | Comments Off on Screen Android Landscape Portrait programmatically
2,752 views

Button Android

Google Android button example source code for developers. // get handle Button myButton; myButton = (Button)findViewById(R.id.idMyButton); //set focus myButton.requestFocus(); // set background image myButton.setBackgroundResource(R.drawable.backImage); // or myButton.setBackgroundDrawable(getResources().getDrawable( R.drawable.someImage));   // set visibility myButton.setVisibility(View.INVISIBLE); // VISIBLE   ///////// SET LISTENER Button … Continue reading

Posted in Android Examples Code | Tagged , , | Comments Off on Button Android
6,464 views

Display screen size resolution density dimension Android

Get display, screen resolution – dimension Android phone development example source code. Display display = getWindowManager().getDefaultDisplay(); int nWidth = display.getWidth(); int nHeight = display.getHeight();   DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); //get density per inch for example: 120 , 160 … Continue reading

Posted in Android Examples Code | Tagged , , , , | Comments Off on Display screen size resolution density dimension Android
8,776 views

Show keyboard in WebView Android example

Show keyboard if WebView input have focus Android apps development example source code. WebView webview;   //in onCreate   webview = (WebView) findViewById(R.id.idWebviewPda); webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl("http://android.okhelp.cz");   webview.requestFocus(View.FOCUS_DOWN); webview.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) … Continue reading

Posted in Android Examples Code, Bitmap, drawing | Tagged , , , | Comments Off on Show keyboard in WebView Android example
3,874 views

Show keyboard

Show keyboard Android phone apps development example source code. // ActivityClass.java InputMethodManager showSoftInput; Button hBtnKeyboardShow ; //onCreate showSoftInput = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);   hBtnKeyboardShow = (Button)findViewById(R.id.btnKeyboardShow); hBtnKeyboardShow.setOnClickListener(myButtonListener); // END onCreate   //button listener private OnClickListener myButtonListener = new OnClickListener() { public void … Continue reading

Posted in Android Examples Code | Tagged , , , | Comments Off on Show keyboard
7,176 views

Random number Java

Generate random number Android Java example source code. Random rand = new Random(); int i = rand.nextInt() % 256; // range -255 +255 System.out.print(i + "\n"); // -184 i = Math.abs(rand.nextInt() % 12); // range 0 +11 System.out.print(i); // 7 … Continue reading

Posted in Android Examples Code, Array,List,Collections | Tagged , , , , | Comments Off on Random number Java
5,357 views

Read file from URL

Read file from URL to array of byte and convert to UTF-8 String Android examle source code. URL urlLoc = new URL("http://myweb.com/myfile.html"); URLConnection conexion = urlLoc.openConnection(); conexion.setConnectTimeout(4000); conexion.setReadTimeout(1000); conexion.connect();   // downlod the file InputStream input = new BufferedInputStream(urlLoc .openStream()); … Continue reading

Posted in Android Examples Code | Tagged , , , , , | Comments Off on Read file from URL
3,946 views

Download file from URL

Download image file from URL to ImageView Java Android source example code. Context context = thisClass.this; Drawable image = ImageOperations(context, "http://android.okhelp.cz/images/adictionary/ad_4.png" ,"image.jpg"); ImageView imgView; imgView = (ImageView)findViewById(R.id.idImageView); imgView.setImageDrawable(image);   private Drawable ImageOperations(Context ctx, String url, String saveFilename) { try { … Continue reading

Posted in Android Examples Code, Bitmap, drawing | Tagged , , , , , , , , | Comments Off on Download file from URL