View

Thursday 17 May 2012

How to use Logcat Backup file in SD card

I used sample application to Backup the Logcat file in SD card.First it create the Sample_log_file.txt in the SD card Location and then we give  write to read the logcat file command like -d -f

The following code is
try {
          File filename = new File(Environment.getExternalStorageDirectory()+"/Sample_log_file.txt");
          filename.createNewFile();
          String cmd = "logcat -d -f "+filename.getAbsolutePath();
          Runtime.getRuntime().exec(cmd);
       } catch (IOException e) {
          e.printStackTrace();
        }
You must give the permission in AndroidManifest.xml
 <uses-permission android:name="android.permission.READ_LOGS"/>
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Go and check the file in DDMS->open File Explorer->open Mnt(management)->SD Card->sample_log_file.txt
  



             /    **Log file shown in the word**/



Saturday 5 May 2012

Notification

How to use Notification in Android?


Android represent the Notifications by using Notification class.We have to create a notification by using NotificationManager class,it can be received from the Activity via getSystemService() method.

Eg: NotificationManager notificationManager = (NotificationManager)getSystemService (NOTIFICATION_SERVICE);


Here i use two edit text for giving the email and message  and one button for create a notification.
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <EditText
        android:id="@+id/username_et"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
    android:inputType="text"/>
    <EditText
        android:id="@+id/mess_et"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="5dp"
        android:inputType="text" />
    <Button
        android:id="@+id/button1"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:onClick="createNotification"
        android:text="Create Notification" android:layout_gravity="center_horizontal"/>
   
</LinearLayout>

Tuesday 1 May 2012

How to use Image can convert into ByteArray

How to Image can convert into ByteArray
Here I used barcode image can convert into Byte Array and the Byte Array can reconvert into the original form.I used two Buttons,textview for values and one static image then ByteArrayOutputStream for conversion.
Here java code ,The class name as ImageConversion.java

public class ImageConvertScreen extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
  Button img_byte,byte_img;
  ImageView image;
  TextView value;
  public ByteArrayOutputStream bos;
  public Bitmap bm;
  public byte[] bitmapdata;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);      
        image = (ImageView) findViewById(R.id.img_convert);
        value=(TextView)findViewById(R.id.convert_txt);
        img_byte =(Button)findViewById(R.id.img_byte);
        byte_img =(Button)findViewById(R.id.byte_img);
        img_byte.setOnClickListener(this);
        byte_img.setOnClickListener(this);
     
     
       bm = BitmapFactory.decodeResource(getResources(),R.drawable.barcode);
       bos = new ByteArrayOutputStream();
       bm.compress(Bitmap.CompressFormat.JPEG, 40 , bos);
      
      
    }
    public void onClick(View v) {
  if (v == img_byte) { 
   bitmapdata = bos.toByteArray();
      Log.w("Image Conversion", String.valueOf(bitmapdata.length));
      String converted_txt="";
         for (int i = 0; i < bitmapdata.length; i++) {
       Log.w("Image Conversion", String.valueOf(bitmapdata[i]));
          converted_txt=converted_txt+bitmapdata[i];
         }
         value.setText(converted_txt);
         value.setVisibility(View.VISIBLE);
         image.setVisibility(View.INVISIBLE);
  
  } else if (v==byte_img){
    bm = BitmapFactory.decodeByteArray(bitmapdata , 0, bitmapdata .length);
        image.setImageBitmap(bm);
        image.setVisibility(View.VISIBLE);
        value.setText("");
        value.setVisibility(View.INVISIBLE);
        Log.w("Image Conversion", "converted");

  }
    }
   
}