Today in this tutorial we will make a small app to have some fun. Can you imagine how you will feel if your mobile screen cracks? Or, How much fun it will be to see your friend’s face when his/her mobile screen cracks while running application you shared with them. Let us create an android app to give that screen crack effect (visual and sound).
First, we need to create a layout with an image viewer with transparent background. This image view is for the broken screen effect. Once the layout is ready, we will add some nice sound to give the effect that a glass actually cracks. The sound will be added to the Java class file by using the MediaPlayer class.
Follow the steps below to make this app and have fun:
Step1: Create a new android project in your android IDE.
Step2: Create a new folder raw to you res folder and copy the sound file there.
Step3: Copy a transparent screen crack image into your drawables.
Step4: Write following into your manifest file:
<application android:allowBackup="true" android:label="ScreenCrackApplication" android:theme="@style/AppTheme" > <activity android:name="com.screencrackapplication.MainActivity" android:theme="@android:style/Theme.Translucent" android:label="ScreenCrackApplication" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
Step5: Write following into your layout file:
<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:background="#80000000" tools:context=".MainActivity" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image" /> </RelativeLayout>
Step6: Write following into your main activity java file:
package com.screencrackapplication; import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; public class MainActivity extends Activity { MediaPlayer objPlayer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); objPlayer = MediaPlayer.create(this,R.raw.crack); objPlayer.start(); } }
Step7: Run to seen the output below:
See my previous blog I have published on Android L Recycler and CardView combined in Android L
Top 10 Android App Development Trends | 2020 Guide
5 Best Resources to Get Started with Android Nougat
Android Studio Introduction
Services – An Android Component
Applying MediaCodec On An Open Source Android Audio Player
5 Most Used Android Testing Frameworks
Android Language Highlights A Developers Perspective
Android KitKat Development