2015-10-04 86 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

相關問題