【发布时间】:2015-10-04 22:33:41
【问题描述】:
我想创建一个自定义通知来直接从通知中回复短信,如下所示:
据我了解,正常通知的高度必须为 64dp,但您可以使用 API >16 中较大的通知作为可扩展通知,但我认为 64dp 高度适合我的情况。我使用了这段代码,但是当我的自定义通知布局有编辑文本时它会崩溃:
RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.widget);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContent(remoteViews);
Intent resultIntent = new Intent(context, MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(100, mBuilder.build());
错误:
android.app.RemoteServiceException: Bad notification posted from package com.example.x: Couldn't expand RemoteViews for: StatusBarNotification
我该怎么办?
【问题讨论】:
-
"创建自定义通知,包括 Edit text android" -- 你不能将
EditText放在RemoteViews中。 -
为什么?我应该怎么做才能发出自定义通知?
标签: android notifications custom-controls