標籤:lag 點擊 content 圖片 動態 can bubuko show yqi
以前用過一個紅包鎖屏的軟體,第一次開啟手機出現鎖屏,滑動領取收益,當時覺得這功能不錯,就查閱資料,寫了一個案例,
apk運行流程: 進入軟體---》啟動服務---》關閉手機(可先退出應用)--》再開啟手機即可看見鎖定畫面
:
當然這個案例還是有缺點的,沒考慮效能問題。
介面是可以隨意修改的,滑動的是一個自訂控制項。
服務類
public class AppService extends Service { private AppReceiver mLockScreenReceiver; private IntentFilter mIntentFilter = new IntentFilter(); @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } @Override public int onStartCommand(Intent intent, int flags, int startId) { // 監聽螢幕關閉和開啟的廣播必須動態註冊 mIntentFilter.addAction(Intent.ACTION_BOOT_COMPLETED); mIntentFilter.addAction(Intent.ACTION_SCREEN_OFF); mIntentFilter.addAction(Intent.ACTION_SCREEN_ON); mIntentFilter.addAction(Intent.ACTION_TIME_TICK); // 設定廣播的優先順序 mIntentFilter.setPriority(Integer.MAX_VALUE); if (null == mLockScreenReceiver) { mLockScreenReceiver = new AppReceiver(); mIntentFilter.setPriority(Integer.MAX_VALUE); registerReceiver(mLockScreenReceiver, mIntentFilter); Toast.makeText(getApplicationContext(), "AppService", Toast.LENGTH_LONG).show(); } NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setTicker("APP正在運行"); builder.setAutoCancel(false); builder.setContentTitle("APP正在運行"); builder.setContentText("您的收益正在累積"); builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, LockScreenActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)); Notification n = builder.build(); // 通知欄顯示系統表徵圖 startForeground(0x111, n); Parser.killBackgroundProcess(this); return START_STICKY; } @Override public void onDestroy() { if (mLockScreenReceiver != null) { unregisterReceiver(mLockScreenReceiver); mLockScreenReceiver = null; } super.onDestroy(); // 重啟服務 startService(new Intent(this, AppService.class)); }}
源碼有點多就不一一貼出來了,直接下載源碼即可。
有興趣的小夥伴可以參考,一起研究。
源碼點擊下載:https://github.com/DickyQie/android-system
android------鎖屏(手機啟動出現鎖定畫面)