在扩展新版本(SDK18,JB-4.3)NotificationListenerService
的服务中,我想获取通知的状态栏图标。
mStatusBarNotification.getNotification().icon
返回状态栏drawable的资源ID,但该资源ID自然不在我的应用程序的范围/资源范围内。还有mStatusBarNotification.getNotification().largeIcon
(返回Bitmap
),但没有为所有通知设置并返回“错误”图标(展开的通知抽屉中的图像)。
答案 0 :(得分:4)
使用getPackageName()
上的StatusBarNotification
查找发布Notification
的应用。然后,您可以use createPackageContext()
为该软件包获取Context
,然后使用Context
来检索图片(例如,通过getResources()
)。
答案 1 :(得分:0)
这是替代解决方法。
我们可以从import org.apache.spark.sql.{functions => F}
// force the full dataframe into memory (could specify persistence
// mechanism here to ensure that it's really being cached in RAM)
df.cache()
df.count()
// calculate size of full dataframe
val catalystPlan = df.queryExecution.logical
val dfSizeBytes = spark.sessionState.executePlan(catalystPlan).optimizedPlan.stats.sizeInBytes
for (col <- df.columns) {
println("Working on " + col)
// select all columns except this one:
val subDf = df.select(df.columns.filter(_ != col).map(F.col): _*)
// force subDf into RAM
subDf.cache()
subDf.count()
// calculate size of subDf
val catalystPlan = subDf.queryExecution.logical
val subDfSizeBytes = spark.sessionState.executePlan(catalystPlan).optimizedPlan.stats.sizeInBytes
// size of this column as a fraction of full dataframe
val colSizeFrac = (dfSizeBytes - subDfSizeBytes).toDouble / dfSizeBytes.toDouble
println("Column space fraction is " + colSizeFrac * 100.0 + "%")
subDf.unpersist()
}
获取可绘制对象,然后使用customview在通知中显示该可绘制对象。
这是使用android.icon值获取Drawable的方法:
sbn.getNotification().extras.getInt("android.icon")
我的 RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.custom_push_notification);
contentView.setImageViewResource(R.id.image, R.mipmap.ic_launcher);
contentView.setTextViewText(R.id.title, notificationModel.getTitle());
contentView.setTextViewText(R.id.text, notificationModel.getBody());
try {
//now get the context of other app and then get drawable from resoures
Drawable drawable1 = context.createPackageContext(notificationModel.getPackageNmae(), CONTEXT_IGNORE_SECURITY).getDrawable(notificationModel.getIcon());
Bitmap bitmap = drawableToBitmap(drawable1);
contentView.setImageViewBitmap(R.id.image, bitmap);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
是:
notificationModel