Thursday, August 23, 2012

Open Website in mobile


Intent mIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.perceptionsystem.com/"));

startActivity(mIntent);

To kill all process


android.os.Process.killProcess(android.os.Process.myPid());

AudioPalyer Class


package androidexperts.apps.jigsaw;

import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.graphics.AvoidXfermode;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnBufferingUpdateListener;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.media.MediaPlayer.OnVideoSizeChangedListener;
import android.net.Uri;
import android.view.SurfaceHolder;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.MediaController.MediaPlayerControl;

@SuppressWarnings("unused")
public class AudioPlayer
{
String fileName;
Context contex;
Uri path;
MediaPlayer mp;
public AudioPlayer( String name, Context context)
{
fileName=name;
contex=context;
AssetManager am = contex.getAssets();

path = Uri.fromFile(new File("assets/"));

playAudio();

}

public void playAudio()
{
mp = new MediaPlayer();

try {
AssetFileDescriptor descriptor = contex.getAssets().openFd(fileName);
mp.setDataSource( descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength() );
descriptor.close();
mp.prepare();
   mp.start();
   mp.setVolume(5, 5);
 
       
   }
catch (IllegalArgumentException e)
{
  e.printStackTrace();


}
catch (IllegalStateException e)
{

e.printStackTrace();


   }
catch (IOException e)
{
e.printStackTrace();

}
}
public void stop()
{
mp.stop();
}


}

Clearing Bitmap Method


private void unbindDrawables(View view)
{
if (view.getBackground() != null)
{
view.getBackground().setCallback(null);
}
try
{
((ViewGroup) view).removeAllViews();
}
catch (Exception e)
{
e.printStackTrace();
}

}

Close Dialog After Some Second


final Timer mtimer_dialog_dismiss = new Timer();
mtimer_dialog_dismiss.schedule(new TimerTask() {
public void run() {
mDialog.dismiss();
mtimer_dialog_dismiss.cancel();
}
}, 7000);

Animation to Control


Animation anim_text_congrate = AnimationUtils.loadAnimation(ClassName, R.anim.winnermessage);
dialog_text_congreats.startAnimation(anim_text_congrate);