Tuesday, December 27, 2011

Share data android

 Intent msg = new Intent(Intent.ACTION_SEND);
 String[] recipients = { "" }; // this.is@recipient.com
  String[] carbonCopies = { "" }; // hey.another@recipient.
  msg.putExtra(Intent.EXTRA_EMAIL, recipients);
  msg.putExtra(Intent.EXTRA_CC, carbonCopies);
 msg      .putExtra(        Intent.EXTRA_TEXT,        "your text");
  // Change from ApplicationStep class subject line     // Html.
  msg.putExtra(Intent.EXTRA_SUBJECT, ApplicationStep.EMAIL_SUBJECT);     msg.putExtra(Intent.EXTRA_STREAM, Uri.parse(sUri)); // attachment
   msg.setType("image/png");  
startActivity(Intent.createChooser(msg,      "Please choose an email client"));

Monday, December 19, 2011

Get ImageFile form server and Store onto Device's memory and display it

public class DataStoreActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        DownloadFile("image file path www.");
        byte b[] = readInternalStoragePrivate("download.jpg");
       
        Bitmap bmp = BitmapFactory.decodeByteArray(b, 0, b.length);
       
        ImageView imageView = new ImageView(this);
        imageView.setImageBitmap(bmp);
        setContentView(imageView);
    }

    /**
     * Reads a file from internal storage
     * @param filename the file to read from
     * @return the file content
     */
    public byte[] readInternalStoragePrivate(String filename) {
        int len = 1024;
        byte[] buffer = new byte[len];
        try {
            FileInputStream fis = openFileInput(filename);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            int nrb = fis.read(buffer, 0, len); // read up to len bytes
            while (nrb != -1) {
                baos.write(buffer, 0, nrb);
                nrb = fis.read(buffer, 0, len);
            }
            buffer = baos.toByteArray();
            fis.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return buffer;
    }
    /**
     * Writes content to internal storage making the content private to
     * the application. The method can be easily changed to take the MODE
     * as argument and let the caller dictate the visibility:
     * MODE_PRIVATE, MODE_WORLD_WRITEABLE, MODE_WORLD_READABLE, etc.
     *
     * @param filename - the name of the file to create
     * @param content - the content to write
     */
    public void writeInternalStoragePrivate(
            String filename, byte[] content) {
        try {
            //MODE_PRIVATE creates/replaces a file and makes
            //  it private to your application. Other modes:
            //    MODE_WORLD_WRITEABLE
            //    MODE_WORLD_READABLE
            //    MODE_APPEND
            FileOutputStream fos =
               openFileOutput(filename, Context.MODE_PRIVATE);
            fos.write(content);
            fos.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    /**
     * Delete internal private file
     * @param filename - the filename to delete
     */
    public void deleteInternalStoragePrivate(String filename) {
        File file = getFileStreamPath(filename);
        if (file != null) {
            file.delete();
        }
    }

    public  void DownloadFile(String fileURL) {
        try {
              // File file = new File(fileName,);
              // file.createNewFile();
             //  FileOutputStream f = new FileOutputStream(file);
            FileOutputStream f = openFileOutput("download.jpg", Context.MODE_PRIVATE);
            URL u = new URL(fileURL);
            HttpURLConnection c = (HttpURLConnection) u.openConnection();
            c.setRequestMethod("GET");
            c.setDoOutput(true);
            c.connect();
        

            InputStream in = c.getInputStream();

            byte[] buffer = new byte[1024];
            int len1 = 0;
            while ((len1 = in.read(buffer)) > 0) {
                f.write(buffer, 0, len1);
            }
            f.close();
          // Log.d("Download Completed", )
        } catch (Exception e) {
           e.printStackTrace();
        }

    }
}

Friday, December 16, 2011

EditText limitation InputFilter


// you can add length limit to edit text using InputFilter .

InputFilter lengthFilter = new InputFilter.LengthFilter(30);
editText.setFilters(new InputFilter[]{lengthFilter});
 //want one line of text from the user
 editText.setSingleLine(true);

Tuesday, December 13, 2011

Simple Android Audio record Example Android


public class AudioRecorder {
  final MediaRecorder recorder = new MediaRecorder();
  public void start() throws IOException {
  
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFile(sdCardPath+"/xyz.3gp");
    recorder.prepare();
    recorder.start();
  }

 
  public void stop() throws IOException {
    recorder.stop();
    recorder.release();
  }

}

Monday, December 5, 2011

ProgressDialog in android


ProgressDialog progressDialog = null;
   
// ...
    progressDialog
= ProgressDialog.show(this, "Please wait...", true);
   
new Thread() {
       
public void run() {
           
try{
                 
// Grab your data                                                
           
} catch (Exception e) { }

           
// When grabbing data is finish: Dismiss your Dialog
            progressDialog
.dismiss();
       
}
   
}.start();


ProgressDialog using Handler Use


Step 1: Create Global Handler Class.
private EventHandler mEventHandler = new EventHandler();


class EventHandler extends Handler {
int tempMsg = 0;

@Override
public void handleMessage(Message msg) {
try {

switch (msg.what) {
case 1:
// call method whatever you want.
break;

dialog.dismiss();

} catch (Exception e) {
Log.d("XReader", "Error in " + e.getMessage());
}
}
};



step2: call Hender using Msg
ProgressDialog dialog = ProgressDialog.show(XReaderActivity.this, "", "Please wait",true);
Message message = new Message();
message.what = 1;
mEventHandler.sendMessage(message);


Friday, December 2, 2011

ESRI using Eclipse setup guide


Please follow these steps to install the ArcGIS for Android 1.0 Beta Eclipse plug-ins:
1. Start Eclipse, then select Help > Install New Software....

2. In the top-right corner, Click Add.
3. In the Add Repository dialog that appears, enter “ArcGIS Android” for the Name and the following URL for the Location: http://downloads.esri.com/software/arcgis/android
4. In the Available Software dialog, select the checkbox next to ArcGIS for Android and click Next.
5. In the next window, you'll see two plug-ins to be installed. Click Next.

6. Display the License text by clicking on "IMPORTANT-READ CAREFULLY". Read the license text, then click the radio button to accept the license agreements, then click Finish.
7. When the installation completes, restart Eclipse.
* Notes for users of ArcGIS for Android Early Adopter release only
If you had installed the plug-ins for the ArcGIS for Android Early Adopter release, please refer to the Help for ArcGIS API for Android > Esri’s Eclipse tooling > Updating the plug-ins for installation instructions.


Hw to use android:layout_weight


Use android:layout_weight
<LinearLayout 
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:weightSum="100"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <LinearLayout 
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_weight="70" >

        </LinearLayout>
        <LinearLayout android:id="@+id/widget32" android:orientation="horizontal"
            android:layout_weight="30" android:layout_width="fill_parent"

            android:layout_height="wrap_content">

        </LinearLayout>
    </LinearLayout>
content -->