how to play audio file in android

Simply you can use MediaPlayer and play the audio file. Check out this nice example for playing Audio: public void audioPlayer(String path, String fileName){ //set up MediaPlayer MediaPlayer mp = new MediaPlayer(); try { mp.setDataSource(path + File.separator + fileName); mp.prepare(); mp.start(); } catch (Exception e) { e.printStackTrace(); } }

Launching activity from widget

Bringing this way back from the dead, but I had a similar problem and I think I finally solved it… like you, I had a PendingIntent that I attached to the RemoteView. Sometimes it would work, and sometimes it would fail. It was driving me crazy. What I found from a tooltip on the PendingIntent.getActivty() … Read more

Assign width to half available screen width declaratively

If your widget is a Button: <LinearLayout android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:weightSum=”2″ android:orientation=”horizontal”> <Button android:layout_width=”0dp” android:layout_height=”wrap_content” android:layout_weight=”1″ android:text=”somebutton”/> <TextView android:layout_width=”0dp” android:layout_height=”wrap_content” android:layout_weight=”1″/> </LinearLayout> I’m assuming you want your widget to take up one half, and another widget to take up the other half. The trick is using a LinearLayout, setting layout_width=”fill_parent” on both widgets, and setting layout_weight … Read more

How to show Dialog in onCreate method?

you can use ProgressDialog Class with the Help of Handler Class. This way you can achieve what you want to do. progDailog = ProgressDialog.show(loginAct,”Process “, “please wait….”,true,true); new Thread ( new Runnable() { public void run() { // your loading code goes here } }).start(); Handler progressHandler = new Handler() { public void handleMessage(Message msg1) … Read more

How to save the image to SD card on button Click android [closed]

First, you need to get your Bitmap. You can already have it as an object Bitmap, or you can try to get it from the ImageView such as: BitmapDrawable drawable = (BitmapDrawable) mImageView1.getDrawable(); Bitmap bitmap = drawable.getBitmap(); Then you must get to directory (a File object) from SD Card such as: File sdCardDirectory = Environment.getExternalStorageDirectory(); … Read more

Incorrect Coordinates From getLocationOnScreen/getLocationInWindow

I ended up solving this issue by determining the height of the status/notification bar like so: View globalView = …; // the main view of my activity/application DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics(dm); int topOffset = dm.heightPixels – globalView.getMeasuredHeight(); View tempView = …; // the view you’d like to locate int[] loc = new int[2]; … Read more