android------鎖屏(手機啟動出現鎖定畫面)

來源:互聯網
上載者:User

標籤: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------鎖屏(手機啟動出現鎖定畫面)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.