Lets have some fun. All study and no play makes jack a dull boy. Let us create a quick android app and have some fun. How will it feel to crack your mobile screen? Let us create an android app to give that screen crack effect (visual and sound). Shall we jump direct to the steps and leave the gyan.
First step, we should create a layout with a image view with transparent background. This image view is for the broken screen effect. Source code for this layout is as follows,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="clip_vertical" tools:context=".MainActivity" > <ImageView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:src="@drawable/screen_crack_transparent" /> </RelativeLayout>
It will be cool if we add some nice sound effect. The sound will be added with java class file by using the MediaPlayer class. We should use a nice sound file which mimics the sound when a glass cracks.
In a previous tutorial we have seen about how to play audio in android and that will come handy now.
Complete source code for the java class is shown below,
package com.javapapers.android.screencrack; import android.os.Bundle; import android.app.Activity; import android.media.MediaPlayer; import com.javapapers.android.screencrack.R; public class MainActivity extends Activity { MediaPlayer objPlayer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); objPlayer = MediaPlayer.create(this,R.raw.breakingscreen); objPlayer.start(); } }
By running this android app with your real mobile device you can have great fun, than in the emulator.
Comments are closed for "Screen Crack Android App".
Hi Joe i need your help.would you know how to auto answer the call in android 3.0+
please reply…………
its very nice and so simple thanks for posting
Is it possible simulate some kind of vibration or shock along with this?
Can you share the code ?
hello, where i can get the image screen_crack_transparent ?
Nice one.. Thank u.. :)
Could u please Explain briefly hashcode-and-equals concept.
Hash code and equals are overridden methods form the object class. These methods will be overridded when you want to get the hashcode of the object and equals method which returns boolean for comparing objects
Very nyc
Code not working
and please please explain me this line–>
objPlayer = MediaPlayer.create(this,R.raw.breakingscreen);
Code not working
and please please explain me this line–>
objPlayer = MediaPlayer.create(this,R.raw.breakingscreen);
You are clearing my concepts & it helping me lot…Thanks
can we add shocking music are vibrating in it?
Yes Muzamal, sure thats possible. Shortly I will add that code too.
how to get this example code..