Android:O泡果奶——来场恶作剧
Posted zstar-_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android:O泡果奶——来场恶作剧相关的知识,希望对你有一定的参考价值。
前年的时候,不知有多少大学生成为“一份礼物”的受害者,我也亲身经历,不过我没中招,而是亲眼目睹周围人的社死,到了去年,O泡果奶事件又风靡一阵,当时有人就通过反编译得到源代码,发现是用lua写的。正好最近在学android,想通过java复现一下。作为初学者,还是有些难度。幸好看见有大佬已经先人一步写过了,于是拿来略作修改,顺便可以整蛊朋友。
原链接:https://www.lanzoui.com/b0dw9plxe
我将背景音乐换成了周星驰经典的狂笑,图片也换得鬼畜了一些,下面放一下核心代码:
activity_main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:src="@drawable/zhou"
android:layout_width="match_parent"
android:layout_height="500dp"
android:scaleType="fitXY"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="你快乐吗?快乐就和我一起啸吧-v-"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<Button
android:layout_width="wrap_content"
style="?android:attr/buttonStyleSmall"
android:layout_height="wrap_content"
android:text="点击我退出程序"
android:id="@+id/activitymainButton"/>
</LinearLayout>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.edu.cdut.egao">
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"></uses-permission>
<application
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@drawable/icon"
android:theme="@style/AppTheme"
android:resizeableActivity="false">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name="MusicService" />
<meta-data
android:name="android.max_aspect"
android:value="4.0"/>
</application>
</manifest>
MainActivity.java
package cn.edu.cdut.egao;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.os.Bundle;
import android.view.WindowManager;
import android.view.KeyEvent;
import android.os.Build;
import android.view.View;
import android.widget.Toast;
import android.media.AudioManager;
import android.content.Context;
import android.content.Intent;
import android.view.Window;
import android.widget.Button;
public class MainActivity extends Activity
public AudioManager am;
//需要点击次数满足才会退出
private int num = 100;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
//去掉标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//防止重新加载
if (!this.isTaskRoot())
Intent mainIntent = getIntent();
String action = mainIntent.getAction();
if (mainIntent.hasCategory(Intent.CATEGORY_LAUNCHER) && action.equals(Intent.ACTION_MAIN))
finish();return;
//隐藏状态栏标题栏及导航栏
hideLaLayout();
//获取音频服务
am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
//启动线程循环设置音量
new Thread()
public void run()
//这儿是耗时操作,完成之后更新UI;
while(true)
final int m = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
runOnUiThread(new Runnable()
@Override
public void run()
//更新UI
am.setStreamVolume(AudioManager.STREAM_MUSIC, m, AudioManager.FLAG_PLAY_SOUND);
);
try
sleep(500);
catch (InterruptedException e)
.start();
//启动服务播放音乐
final Intent intent = new Intent(getApplicationContext(),MusicService.class);
startService(intent);
//按钮点击事件
final Button bt = findViewById(R.id.activitymainButton);
bt.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View p1)
if(num != 0)
num--;
bt.setText("再点"+num+"下就关闭程序");
else
//停止服务并关闭音乐退出软件
stopService(intent);
finish();
);
@Override
protected void onRestart()
super.onRestart();
hideLaLayout();
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
if(keyCode==KeyEvent.KEYCODE_HOME|| keyCode == KeyEvent.KEYCODE_BACK || keyCode== KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP)
Toast toast = Toast.makeText(this,null,Toast.LENGTH_LONG);
toast.setText("放弃吧,没用的!");
toast.show();
return true;
return super.onKeyDown(keyCode, event);
private void hideLaLayout()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
// 全屏显示,隐藏状态栏和导航栏,拉出状态栏和导航栏显示一会儿后消失。
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
else
// 全屏显示,隐藏状态栏
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
MusicService.java:
package cn.edu.cdut.egao;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.media.MediaPlayer;
public class MusicService extends Service
private MediaPlayer player;
@Override
public IBinder onBind(Intent p1)
return null;
@Override
public void onStart(Intent intent, int startId)
super.onStart(intent, startId);
player = MediaPlayer.create(this,R.raw.audio);
player.setLooping(true);
player.start();
@Override
public void onDestroy()
super.onDestroy();
player.stop();
效果:
点击100次按钮可以退出程序,嗯~真是非常人性呢(O(∩_∩)O)
以上是关于Android:O泡果奶——来场恶作剧的主要内容,如果未能解决你的问题,请参考以下文章