Android O 8.0 Notification 源码分析(二)

本编文章针对AndroidO 8.0代码讲述。此版本的SystemUI和Notification较之前版本有一些改动。

本编文章讲述展示过程: System Notification --> SystemUI --> Display Notifications。

第一编文章《Android O 8.0 Notification 源码分析(一)》讲述生成过程:

App create Notification ----> System's  NotificationManagerService

此便文章的目的为方便自己回忆和给需要的同学参考下。

还是先把整体流程图贴出来:

咱们直接从StatusBar的start()方法开始,到底SystemUI怎么重启的流程,咱们下回分解。

步骤1,2,3,4,5,5,6,7,8,10,11,13:为SystemUI的Statusbar,Navigationbar,Notificationpanel自定义控件的初始化。

步骤15:初始化NotificationListenerWithPlugins,并且注册:

public class NotificationListenerWithPlugins extends NotificationListenerService implements
        PluginListener<NotificationListenerController> {
        //下面只列出了类中方法名,具体实现自己翻代码。
        registerAsSystemService();
        unregisterAsSystemService();
        getActiveNotifications();
        getCurrentRanking();
        ...
}

下面在start()方法注册service:

        // Set up the initial notification state.
        try {
            mNotificationListener.registerAsSystemService(mContext,
                    new ComponentName(mContext.getPackageName(), getClass().getCanonicalName()),
                    UserHandle.USER_ALL);
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to register notification listener", e);
        }

下面代码为在destroy()方法中注销service:

 public void destroy() {
        // Begin old BaseStatusBar.destroy().
        mContext.unregisterReceiver(mBaseBroadcastReceiver);
        try {
            mNotificationListener.unregisterAsSystemService();
        } catch (RemoteException e) {
            // Ignore.
        }
}

步骤9,12,14,16,18:为listener的回调方法会调用 

步骤17,19 StatusBar的addNotification(),updateNotification()方法;

public void addNotification(StatusBarNotification notification, RankingMap ranking)
            throws InflationException {
        String key = notification.getKey();
        if (DEBUG) Log.d(TAG, "addNotification key=" + key);

        mNotificationData.updateRanking(ranking);
        Entry shadeEntry = createNotificationViews(notification);
        ...
        //提示方式
    }

步骤20,21:

protected NotificationData.Entry createNotificationViews(StatusBarNotification sbn)
            throws InflationException {
        NotificationData.Entry entry = new NotificationData.Entry(sbn);
        Dependency.get(LeakDetector.class).trackInstance(entry);
        entry.createIcons(mContext, sbn);
        // Construct the expanded view.
        i
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值