2015-10-04 85 views
1

我想创建一个自定义通知直接从通知回复短信是这样的:创建自定义通知,包括编辑文本的Android

enter image description here

正如我所理解的正常通知必须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 

我应该怎么办?

+0

“创建包含编辑文本android的自定义通知” - 您无法在“RemoteViews”中放置“EditText”。 – CommonsWare

+0

为什么?我应该怎么做才能做出定制通知? –

回答

2

Create custom notification including Edit text android

你不能把一个EditText部件为Notification,应用小工具,或其他任何使用RemoteViews

why?

因为这就是如何编写RemoteViews。您仅限于certain widgets and containers

what should I do to make that custom notification?

重新设计它不涉及EditText

+0

是否有其他方式(不是远程viwes)创建自定义通知? –

+0

@Mohammad:不适用于应用程序。 – CommonsWare

+1

https://developer.android.com/reference/android/app/RemoteInput.html – JakeWilson801

相关问题