Friday, 11 October 2019

Prohibit Screenshot in your android App

Prohibit Screenshot in your android App.


If you want to stop screenshot in all screen of your app then you need to create a BaseActivity and extend this activity to all your activity in which you want to stop screenshot.
Add below mentioned line in onCreate method of BaseActivity.
--------------------------- OR -----------------------------
If you want to prohibit screenshot in particular screen then add below mentioned line if specific activity.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, 
WindowManager.LayoutParams.FLAG_SECURE);

Friday, 22 April 2016

Gson Json to Arraylist

  • Copy below mentioned code and paste in GSONUTILS file
    public static <T> ArrayList<T> fromJsontoArrayList(
    String string, Class<T> model)
    {
    
     Gson gson = new GsonBuilder().create();
     T gfromat = null;
     ArrayList<T> localArrayList = new ArrayList<T>();
     try
     {
    
     JSONArray jsonInner = new JSONArray(string);
     int i = 0;
     while (i < jsonInner.length())
     {
     gfromat = gson.fromJson(jsonInner.get(i).toString(), model);
     localArrayList.add(gfromat);
     i++;
    
     }
    
     }
     catch (Exception e)
     {
      Log.e("GsonUtils","Amit exception["+e.getMessage()+"]");
     }
    
     return localArrayList;
    }
  • call this method like this fromJsontoArrayList("jsonstring",beanclass.class)

Friday, 11 March 2016

Convert file size to readable format

[KEY : convert file size, readable file size, convert in]

Convert file size to readable format

  1. Copy below method
    public static String convertSize(long size)
    {
    
    String sizeIn[] = new String[] { "KB", "MB", "GB", "TB" };
    String ret = "";
    if (size >= 1024)
    {
     int devider = 1024;
     int counter = 0;
     while (size / devider > 1024)
     {
      counter++;
      devider *= 1024;
      
     }
     ret = String.format("%.2f", (double) size / devider) + " " + sizeIn[counter];
     
     return ret;
    } else
    {
     ret = size + " bytes";
    }
    return ret;
    }
    
  2. Get file length and call above method
    convertSize(new File("file.txt").length())

Thursday, 11 June 2015

Merge Two Displayer (Universal Image Loader Android)

Merge Two Displayer (Universal Image Loader Android)

  1. Create a class named TwoDisplayer
    import android.graphics.Bitmap;
    import android.graphics.BitmapShader;
    import android.graphics.Canvas;
    import android.graphics.ColorFilter;
    import android.graphics.Matrix;
    import android.graphics.Paint;
    import android.graphics.PixelFormat;
    import android.graphics.Rect;
    import android.graphics.RectF;
    import android.graphics.Shader;
    import android.graphics.drawable.Drawable;
    import android.view.View;
    import android.view.animation.AlphaAnimation;
    import android.view.animation.DecelerateInterpolator;
    import android.widget.ImageView;
    
    import com.nostra13.universalimageloader.core.assist.LoadedFrom;
    import com.nostra13.universalimageloader.core.display.BitmapDisplayer;
    import com.nostra13.universalimageloader.core.imageaware.ImageAware;
    import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;
    
    
    
    public class TwoDisplayer implements BitmapDisplayer
    {
     protected int cornerRadius;
     protected int margin;
    
     private int durationMillis;
     private boolean animateFromNetwork;
     private boolean animateFromDisk;
     private boolean animateFromMemory;
    
    
     public TwoDisplayer(int cornerRadiusPixels, int fadeInTime){
    
      setCorner(cornerRadiusPixels,0,"");
      setFader(fadeInTime,true,true,true);
    
     }
     public void setCorner(int cornerRadiusPixels, int marginPixels,String dummy) {
      this.cornerRadius = cornerRadiusPixels;
      this.margin = marginPixels;
     }
     public void setFader(int durationMillis, boolean animateFromNetwork,
     boolean animateFromDisk,boolean animateFromMemory) {
      this.durationMillis = durationMillis;
      this.animateFromNetwork = animateFromNetwork;
      this.animateFromDisk = animateFromDisk;
      this.animateFromMemory = animateFromMemory;
     }
     @Override
     public void display(Bitmap bitmap, ImageAware imageAware, LoadedFrom loadedFrom)
     {
    
      if (!(imageAware instanceof ImageViewAware)) {
       throw new IllegalArgumentException("ImageAware should
     wrap ImageView. ImageViewAware is expected.");
      }
      imageAware.setImageDrawable(new RoundedDrawable(bitmap, cornerRadius, margin));
      if ((animateFromNetwork && loadedFrom == LoadedFrom.NETWORK) || (animateFromDisk && loadedFrom == LoadedFrom.DISC_CACHE) ||
        (animateFromMemory && loadedFrom == LoadedFrom.MEMORY_CACHE)) {
       animate(imageAware.getWrappedView(), durationMillis);
      }
     }
    
    
     /**
      * Animates {@link ImageView} with "fade-in" effect
      *
      * @param imageView {@link ImageView} which display image in
      * @param durationMillis The length of the animation in milliseconds
      */
     public static void animate(View imageView, int durationMillis) {
      if (imageView != null) {
       AlphaAnimation fadeImage = new AlphaAnimation(0, 1);
       fadeImage.setDuration(durationMillis);
       fadeImage.setInterpolator(new DecelerateInterpolator());
       imageView.startAnimation(fadeImage);
      }
     }
    
     //=========================RoundedDrawable=======================
     public static class RoundedDrawable extends Drawable {
      protected final float cornerRadius;
      protected final int margin;
      protected final RectF mRect = new RectF(),
        mBitmapRect;
      protected final BitmapShader bitmapShader;
      protected final Paint paint;
      public RoundedDrawable(Bitmap bitmap, int cornerRadius, int margin) {
       this.cornerRadius = cornerRadius;
       this.margin = margin;
       bitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
       mBitmapRect = new RectF (margin, margin, bitmap.getWidth() - margin, bitmap.getHeight() - margin);
       paint = new Paint();
       paint.setAntiAlias(true);
       paint.setShader(bitmapShader);
      }
      @Override
      protected void onBoundsChange(Rect bounds) {
       super.onBoundsChange(bounds);
       mRect.set(margin, margin, bounds.width() - margin, bounds.height() - margin);
       // Resize the original bitmap to fit the new bound
       Matrix shaderMatrix = new Matrix();
       shaderMatrix.setRectToRect(mBitmapRect, mRect, Matrix.ScaleToFit.FILL);
       bitmapShader.setLocalMatrix(shaderMatrix);
      }
      @Override
      public void draw(Canvas canvas) {
       canvas.drawRoundRect(mRect, cornerRadius, cornerRadius, paint);
      }
      @Override
      public int getOpacity() {
       return PixelFormat.TRANSLUCENT;
      }
      @Override
      public void setAlpha(int alpha) {
       paint.setAlpha(alpha);
      }
      @Override
      public void setColorFilter(ColorFilter cf) {
       paint.setColorFilter(cf);
      }
     }
    }
    
    
  2. Copy and paste above code
  3. Call from activity / adapter as below
    defaultOptions = new DisplayImageOptions.Builder().cacheOnDisk(true).cacheInMemory(false).imageScaleType(ImageScaleType.EXACTLY).resetViewBeforeLoading(true)
        .displayer(new TwoDisplayer(10, 1000))
    

Monday, 14 July 2014

Dynamically set screen orientation android

Set following code before setting activity layout as follow

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(r.layout.yourlayout);


Sunday, 13 July 2014

Remove / Disable activity header android

Just before setting contentview add the following line

requestWindowFeature(Window.FEATURE_NO_TITLE);


Thursday, 10 July 2014

Slide ViewPager on button click

You have changed ViewPager's page by sliding it. You can also change page by click on next and previous button.

  1. Add two button so called NEXT and PREV in xml.
  2. Instantiate these buttons in your activity. And create a global counter as follow

    int globalPosition = 0;

  3. Now set next click listener. as follow

    // checking if pager can scroll or not
    boolean can = mPager.canScrollHorizontally(1);
    
    if(can)
    {
     mPager.setCurrentItem(++globalPosition,true);
    }
    
    

  4. Set previous button click listener

    boolean can = mPager.canScrollHorizontally(-1);
    if(can)
    {
     mPager.setCurrentItem(--globalPosition,true);
    }
    

  5. Dont forget to update globalPosition on ViewPager page sliding.

    mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
     @Override
     public void onPageSelected(int position) {
      globalPosition = position;
     }
    });
    


Sunday, 6 July 2014

Android ViewPager

ViewPager is nothing but horizontal scroller for entire screens.

  1. Lets begin from xml. Add ViewPager in your xml file. You can copy following code.
    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/your_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
        
  2. Now move to java file(Activity) create instance for ViewPager added in xml. Make sure this Activity extending FragmentActivity not Activity
    mPager = (ViewPager) findViewById(R.id.your_pager);
  3. Now create adapter for pager, create pager instance
    ViewPager mPager;
    PagerAdapter mPagerAdapter;
    public static String [] pageItem = new String[]{"Page 1","Page 2","Page 3"};
     
  4. Initialize adapter object and set adapter to ViewPager.
    mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
    mPager.setAdapter(mPagerAdapter);
  5. Create slider class which should extend FragmentStatePagerAdapter or FragmentPagerAdapter.
    private class ScreenSlidePagerAdapter extends 
        FragmentStatePagerAdapter 
    {
    public ScreenSlidePagerAdapter(FragmentManager fm) {
     super(fm);
    }
    
    @Override
    public Fragment getItem(int position) {
            //
     return new MyFragment(position);
    }
    
    @Override
    public int getCount() {
     return pageItem.length;
    }
    }
  6. Create fragment which will display each screen. It will be slided horizontally.
    public class MyFragment extends Fragment {
     TextView textView;
     int position = 0;
     public MyFragment(int position)
     {
      this.position = position;
     }
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            ViewGroup rootView = (ViewGroup) inflater.inflate(
                    R.layout.my_screen_fragment, container, false);
            
            textView = (TextView)rootView.findViewById(R.id.my_page_tv);
            textView.setText(activityClassObject.pageItem[position]);
            return rootView;
        }
    }
    

Tuesday, 24 June 2014

[KEY : ANDROID CUSTOM CHECKBOX, CUSTOM CHECKBOX]

Custom Checkbox Android

How to create custom checkbox. Applying stylish checkbox Android

  1. Take two images for both states checked and unchecked. In png format.
  2. Create checkbox in xml.
  3. Create new xml file assign appropriate name like "checkbox_button.xml"

    <?xml version="1.0" encoding="utf-8"?>
    <selector 
    xmlns:android="http://schemas.android.com/apk/res/android">
      <!--checked image-->
        <item android:drawable="@drawable/checkbox_checked" 
        android:state_checked="true"/>
      <!--unchecked image-->
        <item android:drawable="@drawable/checkbox" 
        android:state_checked="false"/>
    
    </selector>

  4. Add button property in check box in xml

    android:button="@drawable/checkbox_button"


Monday, 23 June 2014

[KEY : ANDROID FRAGMENT, ACTIVITY, ADD FRAGMENT TO ACTIVITY]

Add Fragment to Activity

  1. Create simple activity with xml.
  2. Go to xml file add framelayout and assign id to it as follow:

     <FrameLayout
            android:id="@+id/your_frame_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="true" />

  3. Create java class with name like "MyFirstFragment.java" and extend fragment.
  4. Go to activity add the following code :

    Fragment myFragment = new MyFirstFragment();
     FragmentManager fragmentManager = getSupportFragmentManager();
     FragmentTransaction fTransaction = fragmentManager
       .beginTransaction()
       .replace(R.id.your_frame_layout, bodyFragment)
       .addToBackStack("myprofile");
       
     fTransaction.commit();
       


Saturday, 21 June 2014

[KEY : FRAGMENT, ADDING FRAGMENT, ANDROID FRAGMENT, CREATING FRAGMENT]

FRAGMENT, ANDROID

Android activity is simple and best way to provide interface to user. Fragment are very similar to activity. But it will be much better if we call it small piece of activity. So an activity can have multiple fragments

Creating fragment in android

  1. Create simple class like "MyFirstFragment.java".
  2. Extend Fragment class into "MyFirstFragment.java".
  3. Fragement is almost ready. Now add required methods into it, Specifically you require two methods onCreateView() and onAttach() as mentioned below :

    @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub return super.onCreateView(inflater, container, savedInstanceState); }


    @Override public void onAttach(Activity activity) { // TODO Auto-generated method stub super.onAttach(activity); }

  4. Inflate your own xml file and return it as view. So finally onCreateView() will look like as below:

    @Override
     public View onCreateView(LayoutInflater inflater, 
       ViewGroup container, Bundle savedInstanceState) {
      
      View localView = inflater.inflate(R.layout.your_xml.xml, 
        container, false);
      
      return localView; //super.onCreateView(inflater, container, savedInstanceState);
     }
    

  5. Create global object of your parent activity

    YourActivity yourActivityObject;

  6. Initialize yourActivityObject in onAttach method so it will look as below:

     @Override
     public void onAttach(Activity activity) {
    
      yourActivityObject = (YourActivity)activity;
    
      super.onAttach(activity);
     }
    

Start / Call new fragment from fragment

 Fragment yourSecondFragment = new YourSecondFragment();

 FragmentManager fm = yourActivityObject.getSupportFragmentManager();

 //yourSecondFragment.setArguments(Bundle) // to pass argument to next fragment.

 fm.beginTransaction().replace(R.id.parent_activity_frame_layout, 
 yourSecondFragment).addToBackStack("myfragmentstring").commit();

 // addToBackStack method before commit is used to implement back button functionality later.  

Adding back button functionality to fragment

In parent activity add onBackPressed() method and paste the following code

int f = getSupportFragmentManager().getBackStackEntryCount();
  Log.v(tag, "onBackPressed ["+f+"]");
  if (f <= 1)
   this.finish();
  else {
   getSupportFragmentManager().popBackStackImmediate();
  }


Tuesday, 14 January 2014

[KEY : SIGNED, UNSIGNED, SINGED AND UNSIGNED APK]

Why signed and unsigned apk.

First of all be clear about signed and unsigned apk. Signed apks keeps its digital signature certificate with it, while unsigned does not. The Android system requires that all installed applications be digitally signed with a certificate whose private key is held by the application's developer. The Android system uses the certificate as a means of identifying the author of an application and establishing trust relationships between applications.

As I guess unsigned apk is for facilitate another user to sign apk with its own key.
Remember the following points.

  • All applications must be signed. The system will not install an application on an emulator or a device if it is not signed.
  • To test and debug your application, the build tools sign your application with a special debug key that is created by the Android SDK build tools.
  • When you are ready to release your application for end-users, you must sign it with a suitable private key. You cannot publish an application that is signed with the debug key generated by the SDK tools.
  • You can use self-signed certificates to sign your applications. No certificate authority is needed.

More detail here

Signing the unsigned apk.
  1. Make sure you have unsigned apk or create it (Open menifest file-> click on Export on Unsigned apk).
  2. Keep your unsigned apk in separate folder.
  3. Find the path of you key.
  4. Open Command Prompt.
  5. jarsigner -verbose -keystore path/of/your/key path/of/your/unsignedApk alias_name_of_key
  6. Key will ask password
  7. Done

Wednesday, 10 July 2013

ListView inside scroll view android

  1. Create a class named "VerticalScroller.java"
  2. Copy the following code and paste into class.
    package com.example.utils;
    
    import android.content.Context;
    import android.util.AttributeSet;
    import android.util.Log;
    import android.view.MotionEvent;
    import android.widget.ScrollView;
    
    public class VerticalScroller extends ScrollView{
    
        public VerticalScroller(Context context) {
            super(context);
        }
    
         public VerticalScroller(Context context, AttributeSet attrs) {
                super(context, attrs);
            }
    
            public VerticalScroller(Context context, AttributeSet attrs, int defStyle) {
                super(context, attrs, defStyle);
            }
    
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            final int action = ev.getAction();
            switch (action)
            {
                case MotionEvent.ACTION_DOWN:
                        Log.i("VerticalScroller", "onInterceptTouchEvent: DOWN super false" );
                        super.onTouchEvent(ev);
                        break;
    
                case MotionEvent.ACTION_MOVE:
                        return false; // redirect MotionEvents to ourself
    
                case MotionEvent.ACTION_CANCEL:
                        Log.i("VerticalScroller", "onInterceptTouchEvent: CANCEL super false" );
                        super.onTouchEvent(ev);
                        break;
    
                case MotionEvent.ACTION_UP:
                        Log.i("VerticalScroller", "onInterceptTouchEvent: UP super false" );
                        return false;
    
                default: Log.i("VerticalScroller", "onInterceptTouchEvent: " + action ); break;
            }
    
            return false;
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            super.onTouchEvent(ev);
            Log.i("VerticalScroller", "onTouchEvent. action: " + ev.getAction() );
             return true;
        }
    }
  3. Go to xml file replace your <scrollview></scrollview> with <com.example.utils.VerticalScroller></com.example.utils.VerticalScroller>
  4. Done

Thursday, 2 May 2013

How to call database onUpgrade method Android

just open your SQLiteHelper class and change the DATABASE_VERSION. (increase its value from previous one)
Run your app again.

Monday, 15 October 2012

Create your own camera app and take images android

  1. Create a SurfaceView as follow (it will interact with camera)

    
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import android.content.Context;
    import android.hardware.Camera;
    import android.hardware.Camera.PreviewCallback;
    import android.util.Log;
    import android.view.SurfaceHolder;
    import android.view.SurfaceView;
    
    public class CameraView extends SurfaceView implements 
    SurfaceHolder.Callback
    {
     SurfaceHolder holder;
     Camera camera;
     public CameraView(Context context) 
     {
      super(context);
      holder=getHolder();
      holder.addCallback(this);
      holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
     }
     public void surfaceChanged(SurfaceHolder holder, int format,
       int width,int height) 
     {
    
      Camera.Parameters parameters=camera.getParameters();
      parameters.set("flash-mode", "on");
      camera.setParameters(parameters);
      camera.startPreview();
     }
     public void surfaceCreated(SurfaceHolder holder) 
     {
      try 
      {
       camera=Camera.open();
       camera.setPreviewDisplay(holder);
      } catch (IOException e) 
      {
       e.printStackTrace();
      }
     }
     public void surfaceDestroyed(SurfaceHolder holder) 
     {
      camera.stopPreview();
      camera.setPreviewCallback(null);
      camera.release();
      camera=null;
     }
    }
    

  2. Now Create front interface for camera Activity

    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import android.app.Activity;
    import android.content.Intent;
    import android.hardware.Camera;
    import android.hardware.Camera.PictureCallback;
    import android.hardware.Camera.ShutterCallback;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.Window;
    import android.widget.*;
    
    public class CameraFront extends Activity
    {
     CameraView camview;
     FrameLayout frame;
     Button Click,Close;
     static String filename; 
     public void onCreate(Bundle bundle)
     {
      super.onCreate(bundle);
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.camframe);
      Click=(Button)findViewById(R.id.buttonClick); 
      Click.setOnClickListener(new Button.OnClickListener(){
    
      public void onClick(View v) {
        
       camview.camera.takePicture(shutterCallback, 
         rawCallback, jpegCallback);
    
       }});
      Close=(Button)findViewById(R.id.buttonClose);
      Close.setOnClickListener(new Button.OnClickListener(){
    
      public void onClick(View v) {
      
       CameraFront.this.finish();
    
       }});
      camview=new CameraView(this);
      frame=(FrameLayout)findViewById(R.id.preview);
      frame.addView(camview);
     }
     ShutterCallback shutterCallback = new ShutterCallback() {
      public void onShutter() {
    
      }
     };
     PictureCallback rawCallback = new PictureCallback() {
      public void onPictureTaken(byte[] data, Camera camera) {
    
      }
     };
     PictureCallback jpegCallback = new PictureCallback() {
      public void onPictureTaken(byte[] data, Camera camera) {
       FileOutputStream outStream = null;
      try {
    
       long d=System.currentTimeMillis();
       filename="/sdcard/"+d+".jpg";
    
       outStream = new FileOutputStream(
         String.format("/sdcard/%d.jpg", d));
       outStream.write(data);
       outStream.close();
    
      } catch (FileNotFoundException e) {
       e.printStackTrace();
      } catch (IOException e) {
       e.printStackTrace();
      } finally {
    
      }
      CameraFront.this.finish();
      //ImageViewer to Show Image taken from camera
      Intent intent=new Intent(CameraFront.this,ImageViewer.class);
      intent.putExtra("imagefile", filename);
      startActivity(intent);
     }
    };
    }
    
    

  3. 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" >
    
        <FrameLayout
            android:id="@+id/preview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1" >
        </FrameLayout>
    
        <LinearLayout
           xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:weightSum="1.0" >
    
            <Button
                android:id="@+id/buttonClick"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_weight="0.5"
                android:text="Click" >
            </Button>
    
            <Button
               android:id="@+id/buttonClose"
               android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight="0.5"
               android:text="Close" >
            </Button>
        </LinearLayout>
    
    </LinearLayout>
    
    

  4. It will store image in sdcard

Sunday, 14 October 2012

Install apk from assets android

  1. Copy/put your apk file in assets folder of your project
  2. Set onClick event of button to install apk. Copy and paste following code
  3. ===============================================
    public void loadMyApk()
    {
    copyAssets(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/" + "BS.apk")), "application/vnd.android.package-archive"); startActivityForResult(intent, 4);
    }
    ===============================================
    private void copyAssets()
    {
    AssetManager assetManager = getAssets(); String[] files = null; try { files = assetManager.list(""); } catch (IOException e) { Log.e("tag", e.getMessage()); } for(String filename : files) { InputStream in = null; OutputStream out = null; try { //fileone=filename; in = assetManager.open(filename); out = new FileOutputStream("/sdcard/" + filename); copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; } catch(Exception e) { Log.e("tag", e.getMessage()); } }
    }
    ===============================================
    private void copyFile(InputStream in, OutputStream out) throws IOException
    {
    byte[] buffer = new byte[1024]; int read; while((read = in.read(buffer)) != -1){ out.write(buffer, 0, read); }
    }

    ===============================================
  4. Its done
In the above process I have copied apk file from assets folder to sdcard and installing from sdcard. If you want to delete from sdcard you can call delete() method for file

Wednesday, 29 August 2012

how to connect to internet on pc using android phone

[KEY : Tethering, Phone Internet, PC Internet]

Tethering mobile internet into PC / Laptop

Assuming that internet is activated on your phone
  1. Connect your android phone to pc
  2. Go to Settings
  3. Wireless and Network settings
  4. Tethering and portable hotspot
  5. USB tethering
Now at your pc
  1. Select "My Network Places"
  2. View Network Connections
here you will have your android phone as one more connection

Thursday, 26 July 2012

Java Hello World (First java program)

[KEY : HELLO WORLD, JAVA FIRST PROGRAM, RUN JAVA PROGRAM] Java Hello World program(first java program)
  1. Make sure class path has been set.(To set class path: Copy your bin folder location-> Right click on "My Computer" icon -> Select Advanced tab -> Click on Environment Variable button -> From System variable pane(lower pane) select path click on Edit button -> At variable value field put semicolon (;) and paste bin folder location and save )
  2. start notepad and copy the following code

    class Helloworld
    {
      public static void main(String str[])
      { 
        system.out.println("Hello World");
      }
    }
    

  3. Save file as Helloworld.java(same as your class name).
  4. Open CMD goto your folder where program is saved.
  5. Type javac Helloworld.java(it will compile you program).
  6. Now run with java Helloworld