vai*_*hav 8 notifications android android-layout remoteview
之前已经问过这个问题,但没有一个答案帮助我发布我的案例.
我正在尝试使用布局文件构建自定义通知.但是我收到以下错误:
android.app.RemoteServiceException:从包com.eswaraj.app.eswaraj发布的错误通知:无法展开RemoteViews:StatusBarNotification(pkg = com.eswaraj.app.eswaraj user = UserHandle {0} id = 8888 tag = null score = 0:通知(pri = 0 contentView = com.eswaraj.app.eswaraj/0x7f030052 vibrate = null sound = null defaults = 0x0 flags = 0x0 kind = [null]))
我的布局文件是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="left">
<com.makeramen.RoundedImageView
android:id="@+id/nImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/profile_image"
android:padding="15dp"
android:scaleType="fitCenter"
app:riv_corner_radius="30dip"
app:riv_border_width="2dip"
app:riv_border_color="#333333"
app:riv_mutate_background="true"
app:riv_oval="true"/>
<TextView
android:id="@+id/nTitle"
android:text="eSwaraj: Your voice is heard"
android:layout_toRightOf="@+id/nImage"
android:paddingTop="12dp"
android:textSize="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/nMessage"
android:layout_below="@+id/nTitle"
android:layout_toRightOf="@+id/nImage"
android:text="Your comaplaint viewed"
android:textSize="15dp"
android:paddingTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/nTime"
android:layout_toRightOf="@+id/nImage"
android:layout_below="@+id/nMessage"
android:textSize="13dp"
android:paddingTop="5dp"
android:text="12:23PM"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我发送通知如下:
public void sendNotification(Context caller, Class<?> activityToLaunch, Bitmap icon, GcmMessageDto gcmMessageDto, int id) {
Intent toLaunch;
RemoteViews remoteViews = new RemoteViews(caller.getPackageName(), R.layout.notification);
if(activityToLaunch != null) {
toLaunch = new Intent(caller, activityToLaunch);
}
else {
toLaunch = new Intent();
}
PendingIntent intentBack = PendingIntent.getActivity(caller, 0, toLaunch, 0);
NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(caller)
.setSmallIcon(android.R.drawable.ic_notification_overlay)
.setContentIntent(intentBack);
remoteViews.setTextViewText(R.id.nMessage, gcmMessageDto.getMessage());
remoteViews.setTextViewText(R.id.nTime, new Date().toString());
if(icon != null) {
remoteViews.setImageViewBitmap(R.id.nImage, icon);
}
mBuilder.setContent(remoteViews);
notifier.notify(id, mBuilder.build());
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
Ima*_*ari 19
不久,
com.makeramen.RoundedImageView
正在弄乱你的工作.
并非所有视图都可以在用于构建自定义通知的RemoteView中使用.根据此官方页面,只有以下内容可用于创建RemoteView:
因此,您必须为修改后的ImageView类找到解决方法,并使用简单的ImageView.
| 归档时间: |
|
| 查看次数: |
8981 次 |
| 最近记录: |