Friday, September 4, 2015

Display Owners information without unlocking your Phone

We cans see the owners information without unlocking your phone,This will be helpful in emergency cases.

Procedure to set the owners infomation using android mobiles

Goto Settings -->Security -->Owners Info --> Enable show owners info on lock screen and enter information there like emergency contact numbers etc.

Wednesday, May 6, 2015

Android Studio shortcuts like Eclipse

As far we are good to use the shortcut controls in eclipse. 
Now we are migrating to Android studio where the shortcuts are different while comparing Android studio and Eclipse.

 Please follow the below steps to enable the eclipse shortcut controls in Android studio if you want to use the same eclipse controls in Android Studio.
  1. Click on File menu
  2. Navigate to “Settings”
  3. Click on Keymap section which is available in left side panel
  4. You can see the keymaps dropdown on the right side panel. Select “Eclipse” from 
  5. Finally, save the settings by clicking on OK button.
Now you will be able to use the same eclipse controls in Android studio.

 Goto Settings -->Security -->Owners Info --> Enable show owners info on lock screen and enter information there like emergency contact numbers etc.  

Monday, March 10, 2014

Add our application into default chooser

activity
android:name=".WalkieTalkieActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.CALL" />
<data android:scheme="tel" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.CALL_PRIVILEGED" />
</intent-filter>
</activity>


By using above code we can add our application to default chooser application in android 

Thursday, January 2, 2014

Finish all activities

 package com.hrupin;  
 import android.app.Activity;  
 import android.content.BroadcastReceiver;  
 import android.content.Context;  
 import android.content.Intent;  
 import android.content.IntentFilter;  
 public abstract class AppBaseActivity extends Activity {  
  public static final String FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION = "com.hrupin.FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION";  
  private BaseActivityReceiver baseActivityReceiver = new BaseActivityReceiver();  
  public static final IntentFilter INTENT_FILTER = createIntentFilter();  
  private static IntentFilter createIntentFilter() {  
  IntentFilter filter = new IntentFilter();  
  filter.addAction(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION);  
  return filter;  
  }  
  protected void registerBaseActivityReceiver() {  
  registerReceiver(baseActivityReceiver, INTENT_FILTER);  
  }  
  protected void unRegisterBaseActivityReceiver() {  
  unregisterReceiver(baseActivityReceiver);  
  }  
  public class BaseActivityReceiver extends BroadcastReceiver {  
  @Override  
  public void onReceive(Context context, Intent intent) {  
   if (intent.getAction().equals(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION)) {  
   finish();  
   }  
  }  
  }  
  protected void closeAllActivities() {  
  sendBroadcast(new Intent(FINISH_ALL_ACTIVITIES_ACTIVITY_ACTION));  
  }  
 }  

Monday, September 2, 2013

Custom camera in android

custom camera in android

 public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {  
 private SurfaceHolder mHolder;  
 private Camera mCamera;  
 private Context mContext;  
 public CameraPreview(Context context, Camera camera) {  
 super(context);  
 mContext = context;  
 mCamera = camera;  
 // Install a SurfaceHolder.Callback so we get notified when the  
 // underlying surface is created and destroyed.  
 mHolder = getHolder();  
 mHolder.addCallback(this);  
 // deprecated setting, but required on Android versions prior to 3.0  
 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);  
 mHolder.setFixedSize(100, 100);  
 }  
 public void surfaceCreated(SurfaceHolder holder) {  
 mCamera.setDisplayOrientation(90);  
 // The Surface has been created, now tell the camera where to draw the  
 // preview.  
 try {  
 mCamera.setPreviewDisplay(holder);  
 mCamera.startPreview();  
 }  
 catch (IOException e) {  
 Log.d(  
 "DG_DEBUG", "Error setting camera preview: " + e.getMessage());  
 }  
 /*try {  
 mCamera.setPreviewDisplay(holder);  
 mCamera.setPreviewCallback(new PreviewCallback() {  
 public void onPreviewFrame(byte[] data, Camera camera) {  
 }  
 });  
 } catch (Exception e) {  
 e.printStackTrace();  
 }*/  
 }  
 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {  
 // If your preview can change or rotate, take care of those events here.  
 // Make sure to stop the preview before resizing or reformatting it.  
 if (mHolder.getSurface() == null) {  
 // preview surface does not exist  
 return;  
 }  
 // stop preview before making changes  
 try {  
 mCamera.stopPreview();  
 }  
 catch (Exception e) {  
 // ignore: tried to stop a non-existent preview  
 }  
 // make any resize, rotate or reformatting changes here  
 // start preview with new settings  
 try {  
 mCamera.setPreviewDisplay(mHolder);  
 mCamera.startPreview();  
 }  
 catch (Exception e) {  
 Log.d(  
 "DG_DEBUG", "Error starting camera preview: " + e.getMessage());  
 }  
 }  
 public void surfaceDestroyed(SurfaceHolder holder) {  
 // empty. Take care of releasing the Camera preview in your activity.  
 }  
 }  
 and use the below method in your activiy which one wants custom camera   
 private  
 void createCamera() {   
 // Create an instance of Camera  
 mCamera = getCameraInstance();  
 // Setting the right parameters in the camera  
 Camera.Parameters params =  
 mCamera.getParameters();  
 // params.setPictureSize(1600, 1200);  
 params.setPictureFormat(PixelFormat.JPEG);  
 params.setJpegQuality(85);  
 mCamera.setParameters(params);  
 // Create our Preview view and set it as the content of our activity.  
 mPreview = new CameraPreview(this, mCamera);  
 FrameLayout preview = (FrameLayout) findViewById(R.id.  
 camera_preview);  
 // Calculating the width of the preview so it is proportional.  
 float widthFloat = (float) (deviceHeight) * 4 / 3;  
 int width = Math.round(widthFloat);  
 // Resizing the LinearLayout so we can make a proportional preview. This  
 // approach is not 100% perfect because on devices with a really small  
 // screen the the image will still be distorted - there is place for  
 // improvment.  
 // LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width, deviceHeight);  
 // preview.setLayoutParams(layoutParams);  
 // Adding the camera preview after the FrameLayout and before the button  
 // as a separated element.  
 preview.addView(  
 mPreview, 0);  
 }  
Take care of releasing the Camera preview in your activity.

Tuesday, November 27, 2012

download data from url using http post

HttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new HttpPost(mcontext.getString(R.string.find_link));
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("name", value);
        try {
            httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
       
        HttpResponse response = null;
        try {
            response = httpclient.execute(httppost);
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        InputStream is = null;
        try {
            is = response.getEntity().getContent();
        } catch (IllegalStateException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        StringBuilder sb = new StringBuilder();
        byte[] buffer = new byte[512];
        int bytes_read = 0;

        try {
            while ((bytes_read = is.read(buffer, 0, buffer.length)) > 0) {
                sb.append(new String(buffer, 0, bytes_read));
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mresult=sb.toString();

Add focus to a view

mhandler.post(new Runnable() {
            public void run() {
                    (EditText ref).requestFocus();                           
               
            }
        });