Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 创建自定义通知,包括编辑文本_Android_Notifications_Custom Controls - Fatal编程技术网

Android 创建自定义通知,包括编辑文本

Android 创建自定义通知,包括编辑文本,android,notifications,custom-controls,Android,Notifications,Custom Controls,我想创建一个自定义通知,直接从通知回复SMS,如下所示: 据我所知,正常通知必须具有64dp高度,但您可以使用API>16中较大的通知作为可扩展通知,但我认为64dp高度适合我的情况。我使用了此代码,但当自定义通知布局包含编辑文本时,它会崩溃: RemoteViews remoteViews = new RemoteViews(getPackageName(),R.layout.widget); NotificationCompat.Builder mBuild

我想创建一个自定义通知,直接从通知回复SMS,如下所示:

据我所知,正常通知必须具有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
我该怎么办


创建自定义通知,包括编辑文本

您不能将
编辑文本
小部件放入
通知
、应用程序小部件或任何其他使用
远程视图
的程序中

为什么?

因为这就是
remoteview
的编写方式。您仅限于

我应该怎么做才能生成自定义通知

重新设计,使其不包含
编辑文本


更新:在Android 7.0+上,您可以使用带有
RemoteInput的
MessagingStyle
通知
接受用户的输入。这与问题的要求不匹配,但它是最接近的选项。

“创建自定义通知,包括编辑文本android”-您不能将
EditText
放在
RemoteView
中。为什么?我应该怎么做才能创建自定义通知?有没有其他方法(不是远程viwes)来创建自定义通知?@Mohammad:不适用于应用程序。@JakeWilson801:是的,这是Android 7.0+设备的一个选项。我在简历上写着@Commonware回应了我的评论。推荐更多答案