Screen Crack Android App

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,

activity_main.xml


<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,

MainActivity.java

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();		
	}

}

Android Output

Android Screen Crack

By running this android app with your real mobile device you can have great fun, than in the emulator.

How to Test Run an Android App in Mobile?

  1. Install the driver needed to synchronize your PC and your mobile device. For example, HTC sync for HTC Explorer mobile phone.
  2. Connect the android mobile device with the PC.
  3. Select the connection type of the driver software needed for synchronization.
  4. Enable USB debugging by Setting->Applications->Development-> USB debugging.
  5. Set target to run application by Run Configuration->Target and then select option and then Apply->Run, as shown below.

Android Run

This Android tutorial was added on 15/01/2013.

Comments on "Screen Crack Android App" Tutorial:

  1. S khan says:

    Hi Joe i need your help.would you know how to auto answer the call in android 3.0+

    please reply…………

  2. Anonymous says:

    its very nice and so simple thanks for posting

  3. Karesh says:

    Is it possible simulate some kind of vibration or shock along with this?

  4. satish says:

    Can you share the code ?

  5. kartik says:

    hello, where i can get the image screen_crack_transparent ?

  6. Rashi.. Coorg.. says:

    Nice one.. Thank u.. :)

  7. suresh says:

    Could u please Explain briefly hashcode-and-equals concept.

  8. Praveen S M says:

    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

  9. Praveen says:

    Very nyc

  10. Rajat says:

    Code not working
    and please please explain me this line–>
    objPlayer = MediaPlayer.create(this,R.raw.breakingscreen);

  11. varun says:

    Code not working
    and please please explain me this line–>
    objPlayer = MediaPlayer.create(this,R.raw.breakingscreen);

  12. Anonymous says:

    You are clearing my concepts & it helping me lot…Thanks

  13. Muzamal says:

    can we add shocking music are vibrating in it?

  14. Joe says:

    Yes Muzamal, sure thats possible. Shortly I will add that code too.

  15. bhavesh says:

    how to get this example code..

Comments are closed for this "Screen Crack Android App" tutorial.