Вы находитесь на странице: 1из 10

pdfcrowd.com open in browser PRO version Are you a developer?

Try out the HTML to PDF API


search this site. . .
Tweet 3 2
HOME APPLICATIONS ANDROID SCREEN CRACK PRANK
Android screen crack prank
POSTED BY ANDROID GURU ON AUG 20, 2012 IN APPLICATIONS | 5 COMMENTS

In this post, we are going to develop an application, its kinda
game which can be used to prank your friends. . Yes, you
want to fool your friends with a simple android application,
just go through the post to develop one for you . I would
like to name this application Screen crack prank.
Applications theme:
Let your friends play the game on your Android phone and
see how the screen cracks and the screen goes black and
also vibrates. Your friends will believe they broke your phone.
You must have already seen such applications in Google play
but creating one such application is really fun!!
Connect with us

Readers
Like US?
Search this site
Powered by Google
Share 12
Like 12 Send Share
Like 854 Send
Home Basics Write For Us Categories Downloads Contact Us Site Map Advanced Search
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
Subscribe
New Visitor? Like what you
read? Then do subscribe to
our blog
Let us start creating the application:
Either you can proceed with the below listings, or you can directly download code.
Create new android project [File >> New >> Android
Project] with project name TapperApp
Click next and select target android device version [I
chose version 2.2]
Click next and enter package name
com.prgguru.android
Click finish
Layout creation:
We will create a simple layout which has one textview to display instructions and one button who is
the hero of Screen Crack Prank app.
Main.xml:
Replace the XML present in /res/layout with the below one:
Powered by Google
Follow us on G+
More Interesting Tutorials
Suggest a topic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/background">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Challenge for you!"
android:textStyle="bold"
android:textColor="#0587d9"
android:textSize="20sp"
android:layout_margin="20dip"
android:gravity="center"
android:id="@+id/title"/>

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000"
android:layout_margin="20dip"
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
The application layout should look like:

Recent posts
Android Autocomplete Textview Example
Android JSON Web Service Tutorial
jQuery Examples
Recent comments
Android Guru on Android Webservice example
Android Guru on How to call Java web service
in android
Android Guru on How to call Java web service
in android
Archives
September 2013 (2)
August 2013 (1)
July 2013 (1)
May 2013 (5)
April 2013 (7)
March 2013 (1)
October 2012 (1)
September 2012 (2)
23
24
25
26
27
28
29
30
31
32
33
34
35
36
android:layout_margin="20dip"
android:text="INSTRUCTIONS:\n\nTry to tap the button 100 times within 30 seconds.\n\nBest of Luck!"
android:id="@+id/blurb"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dip"
android:padding="25dip"
android:text="100"
android:layout_gravity="center"
android:id="@+id/button"/>

</LinearLayout>
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
We have to add few resources before we proceed with writing logic for the application.
Load cracked_screen.png (crack image) under /res/drawable-hdpi folder and glass.ogg (glass
breaking sound file) under /res/raw folder. If raw folder is not created, create one under /res folder.
Application logic:
TapperAppActivity.java:
Logic behind the application is given below:
Open TapperAppAcitivty class under com.prgguru.android package and add the below class. Each line
of code is commented to let you understand the code logic.
August 2012 (9)
July 2012 (9)
June 2012 (7)
Categories
AJAX (1)
Android Developers (1)
Applications (1)
Basics (5)
Broadcast receivers (1)
Call (1)
Camera (2)
Eclipse (2)
Email (1)
Intent (1)
jQuery (1)
JSON (1)
Layout (6)
Localization (2)
Media (3)
Music (3)
Mobile Web Framework (1)
jQuery Mobile (1)
Network (2)
Notifications (1)
System Settings (1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.prgguru.android;

import java.util.Random;
import com.example.tapperapp.R;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Vibrator;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class TapperAppActivity extends Activity implements OnClickListener{
MediaPlayer mPlayer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Set application layout
setContentView(R.layout.main);
//Assign media player object with sound file
mPlayer = MediaPlayer.create(TapperAppActivity.this, R.raw.glass);
//Find the button
((Button) findViewById(R.id.button)).setOnClickListener(this);
}

public void onClick(View v) {
//If our applicaitons' button is clicked
if (v.getId()==R.id.button) {
//Get the button text which is 100
int i = Integer.parseInt(((Button) v).getText().toString());
//Decrement button text value and set it as button text
((Button) v).setText(Integer.toString(--i));
//Create Random object
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
Text to Speech (1)
Toast (1)
Vibrate service (1)
Web Service (4)
widget (4)
Button (2)
seekbar (1)
TextView (1)
Stay in touch!
Email: Enter your email Subscribe
Blog links
Android Home
Google Play
Java blog
About Me
Hi, welcome to Android Tutorial
Blog. I am Udhay - a software
engineer. Let me introduce myself
more formally, Im a normal guy,
engineer by education who is
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//Create Random object
Random gen = new Random();
//If random value btwn (0 - 9)+1 equals to 10 or i is lesser than 50
if ((gen.nextInt(10) + 1 == 10) || (i<50)) {
//Call crack method
crack();
//Make listener to button as null
((Button) v).setOnClickListener(null);
}
}
}

private void crack() {
//Call audio effects method
audibleFX();
//Call visual effects method
visualFX();
//Call vibrate effects method
touchFX();
}

private void audibleFX() {
//Play sound file
mPlayer.start();
}

private void visualFX() {
//Set background with broken glass image
findViewById(R.id.background).setBackgroundResource(R.drawable.cracked_screen);
//Set title textview with color 0x6400ff00
((TextView)findViewById(R.id.title)).setTextColor(0x6400ff00);
//Set blurb textview with color 0x64ffffff
((TextView)findViewById(R.id.blurb)).setTextColor(0x64ffffff);
//Set button with color 0x64cdc9c9
((Button)findViewById(R.id.button)).setBackgroundColor(0x64cdc9c9
}

private void touchFX() {
//Create vibrator object
Vibrator mv = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
//Vibrate for 500 MS
mv.vibrate(new long[]{ 0, 500, 0 }, -1);
}

protected void onDestroy() {
super.onDestroy();
// Release mediaplayer
if (mPlayer != null) {
mPlayer.release();
mPlayer = null;
}
}
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
Add vibrate permission in Androidmanifest.xml:
To know more about how to use vibration service in Android, see Android vibrate example
Demo:
Congratulations, We are done.
Let us test the application:
Right click on the project >> Run as >> Android application >> Choose emulator or device
Tap on the button and see what happens.
engineer by education who is
passionate about Programming and Internet.
Here I am writing about Android and lot about
developing simple android applications. Are you
new/beginner to Android programming and want
to join with me in the journey of learning Android
application development? You are in the right
place then :) Keep me posted with your valuable
feedback and comments. Happy learning!
86
87
}
}
1 <uses-permission android:name="android.permission.VIBRATE" />
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
Download Source Code Download Application(apk)
Entire project is zipped and is available for download. Unzip the downloaded
project and to import the project into eclipse, launch eclipse >> File >> Import.. >>
Choose downloaded project(How to import android project in eclipse). If you just
want to run the application in your mobile and see the output but dont want to hit
your head with source code, download application(apk) file and install it in your
mobile device.
*apk in Android is the installation file simliar to exe in windows.

I hope you enjoyed the post!!
Suggested posts for further reading
You might also like -
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
Tweet 3
reply
aravind
NOVEMBER 30, 2012
nice post
Samuel
NOVEMBER 24, 2012
Hi Ive followed your instruction and have recreated the app using Eclipse, only changing
minor bits such as the android:text= part into using a @string method (This was flagged
by Eclipse) and the file name of the main.xml
After finishing that I tried to run it on an emulator as well as my own Android device.
While at first it runs, it force quitted after playing the glass sound, without displaying the
cracked_glass png as well as any vibration.
I tried using your source code provided at the end of this guide and it works.
Any idea what Ive done wrong?

5 Comments
Android Autocomplete
Textview Example
Android JSON Web
Service Tutorial
How to call Java web
service in android
How to call asp.net
web service in android
Share 12
Like 12 Send Share
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
reply
reply
MrCleanX
OCTOBER 30, 2012
Great post! Great Blog! Just what I need to get rolling in Droid programming. Thanks, and
keep it up!
reply
Wiltshire
OCTOBER 19, 2012
My brother recommended I might like this blog. He was entirely right. This publish truly
made my day. You can not imagine just how a lot time I had spent for this information!
Thank you!
reply
g.gopikrishna
SEPTEMBER 25, 2012
how to remove ram memory in android device using java code or phonegap code .please
provide slolution for me
Leave a Reply
Your email address will not be published. Required fields are marked *
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
Name *
Email *
Website
Comment
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym
title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q
cite=""> <strike> <strong>
Submit Comment
If you like this post, please do click Appreciate
Badge

Вам также может понравиться