RemoteViewsReader
Read RemoteViews information with some black magic way.
Reference
See RemoteViews.
Usage
Read informations
You can read RemoteViews
information like this.
public class NotificationWatcher extends NotificationListenerService {
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
super.onNotificationPosted(sbn);
RemoteViews remoteViews = sbn.getNotification().contentView;
RemoteViewsInfo info = RemoteViewsReader.read(this, remoteViews);
// you can read informations from `info` object.
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
super.onNotificationRemoved(sbn);
}
}
RemoteViewsInfo
contains following informations.
- ApplicationInfo: An information about an application which have built this
RemoteViews
. - Actions: A list of actions the application have committed on
RemoteViews
. - Layout Id: An identity of the
RemoteViews
layout.
Read Actions
The operations for RemoteViews
are stored as a list of Action
. So you can find the action you want like this.
RemoteViewsInfo info = RemoteViewsReader.read(this, remoteViews);
for (RemoteViewsAction action : info.getActions()) {
}
RemoteViewsAction is an abstract type for each concrete operations. We have several types by default, according to AOSP implementation.
- BitmapRefrectionAction
Action forRemoteViews#setImageBitmap()
. - RefrectionAction
Action for various methods declared onRemoteViews
. - RefrectionWithoutParamsAction
Action for various methods without any parameters declared onRemoteViews
. - SetDrawableParamsAction
Action forRemoteViews#setDrawableParameters()
. - SetEmptyViewAction
Action forRemoteViews#setEmptyView()
. - SetOnClickFillInIntentAction
Action forRemoteViews#setOnClickFillInIntent()
. - SetOnClickPendingIntentAction
Action forRemoteViews#setOnClickPendingIntent()
. - SetPendingIntentTemplateAction
Action forRemoteViews#setPendingIntentTemplate()
. - SetRemoteViewsAdapterIntentAction
Action forRemoteViews#setRemoteAdapter()
. - SetRemoteViewsAdapterListAction
Action forRemoteViews#setRemoteAdapter()
. - TextViewDrawableAction
Action forRemoteViews#setTextViewCompoundDrawables()
andRemoteViews#setTextViewCompoundDrawablesRelative()
, . - TextViewDrawableColorFilterAction
Action forRemoteViews#setTextViewCompoundDrawablesRelativeColorFilter()
. - TextViewSizeAction
Action forRemoteViews#setTextViewTextSize()
. - ViewGroupAction
Action forRemoteViews#addView()
andRemoteViews#remoteView()
. - ViewPaddingAction
Action forRemoteViews#setViewPadding()
.
If you would like to use the specific type of action, you can deal with it like this.
RemoteViewsInfo info = RemoteViewsReader.read(this, remoteViews);
for (RemoteViewsAction action : info.getActions()) {
if (!(action instanceof BitmapRefrectionAction))
continue;
BitmapRefrectionAction concrete = (BitmapRefrectionAction)action;
Bitmap bmp = concrete.getBitmap();
}
Limitations
Currently this library contains default actions in AOSP. I've found several types of additional customized actions on some devices, and they are not supported now.
Download
Via Gradle
compile 'com.github.keithyokoma:RemoteViewsReader:1.2.0@aar'
License
Apache License v2
Copyright (C) 2015 KeithYokoma, Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.