Android Development Tips

I am going to be adding small Android code snippet here that I think others can benefit from. I will only show Android code that has worked for me. I can not guarantee that it is the best way of doing it, but I know it will work. I will continue to add more in depth code (e.g. classes) in separate posts.

Creating a folder on the SD card and adding files inside

This will create a folder on the SD card and add a empty file in it. This does not check to see if the user has a SD card inserted. I have not seen a problem not checking first to see if the folder or file is already created. I am sure a problem will raise from not checking first.

        /** create the folder **/
        File soundDirectory = new File("/sdcard/customSound2/"); 

        /** create the file **/
        File soundFile = new File("/sdcard/customSound2/" , "RECORDING.3gp");

        OutputStream out = null;
		try {
			out = new BufferedOutputStream(new FileOutputStream(soundFile));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
        try {
		} catch (IOException e) {
			// TODO Auto-generated catch block

Add permission in the manifest file.

   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Creating Dynamic Buttons Using an array in Android

I had to trim it down my source code to make it more sense. I might have an extra or missing curly bracket.

import android.widget.Button;
import android.widget.LinearLayout;

public class SoundBoardActivity extends Activity {
	int numberRecording= 5;
	Button[] playButtons = new Button[numberRecording];     
        LinearLayout layoutbase;
        LayoutParams param;
    public void onCreate(Bundle savedInstanceState) {
        layoutbase =(LinearLayout) findViewById(;
        param = new LinearLayout.LayoutParams(
        		LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f);   
    for(int i=-0; i < numberRecording; i++){
    	       playButtons[i] = new Button(this);
	       playButtons[i].setPadding(15, 15, 15, 15);
   	       playButtons[i].setText(sharedPreferences.getString(Integer.toString(i), "problem"));   	
   	       playButtons[i].setOnClickListener(new MyClickListener()); // i had a custom clickListener
               playButtons[i].setText("add a sound");        	   

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Graveyard Database Logo

Has everything you want to know about grave yards. Plus has many celebrites and world leaders graves. Pssst it is my other site

Google + Profile
Check out Android Photo Mapping, its a app/site I been working on
Fabulou wholesale Petr Mrazek jersey is back. Best choice to get the wholesale Petr Mrazek jersey is suitable for all style of people.