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.
- Create a new folder /res/ and copy the sound file into it.
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
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?
- Install the driver needed to synchronize your PC and your mobile device. For example, HTC sync for HTC Explorer mobile phone.
- Connect the android mobile device with the PC.
- Select the connection type of the driver software needed for synchronization.
- Enable USB debugging by Setting->Applications->Development-> USB debugging.
- Set target to run application by Run Configuration->Target and then select option and then Apply->Run, as shown below.
nice article.great posting.Android apps are now a days an important part of marketing and almost everyone wishing to use it.
ReplyDeleteMy Pizza Maker app
thanq boss...
Delete