2013-11-25 1 views
1
EditText message = (EditText)findViewById(R.id.mess); 
Notification mNotification = new Notification.Builder(this) 
    .setContentTitle("Remainder!") 
    .setContentText(message) 
    .setSmallIcon(R.drawable.ic_launcher) 
    .setSound(soundUri) 
    .build();  

Его дает мне ошибку говоря ContentText должна быть CharSequence. Я попробовал несколько примеров, но не повезло.Уведомление contenttext из поля EditText

ответ

0

попробовать этот способ

setContentText(message.getText().toString()) 
2

вы должны изменить это:

String name = message.getText().toString(); 

и установить после этого:

.setContentText(name) 
0

ли так:

.setContentText(message.getText().toString())

Проверьте мой вопрос here.

+0

Не работает для обоих методов .. для первого он показывает пустое .. нет сообщения .. и для второго метода приложение сбой .. – Shaunak

+0

@ shree202 .. не может добавить точку с запятой .. точка с запятой должна быть после .build() – Shaunak

+0

oops my error ... –

0

Попробуйте это:

В

@Override 
    protected void onMessage(Context context, Intent intent) 
    { 
    String message = intent.getExtras().getString("message"); 
    generateNotification(context, message); 
    } 




private static void generateNotification(Context context, String message) { 

    int icon = R.drawable.icon; 
     long when = System.currentTimeMillis(); 
    String appname = context.getResources().getString(R.string.app_name); 
    NotificationManager notificationManager = (NotificationManager) context 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    int currentapiVersion = android.os.Build.VERSION.SDK_INT; 
    Notification notification; 

    Intent intent = new Intent(context, youractivity.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 
    intent.putExtra("message", message); 

    int requestID = (int) System.currentTimeMillis(); 
    PendingIntent contentIntent = PendingIntent.getActivity(context, requestID, 
      intent, 0); 

     if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB) { 
      notification = new Notification(icon, message, when); 
      notification.setLatestEventInfo(context, appname, message, 
        contentIntent); 
      notification.flags = Notification.FLAG_AUTO_CANCEL; 
      notificationManager.notify((int) when, notification); 

     } else { 
      NotificationCompat.Builder builder = new NotificationCompat.Builder(
        context); 
      notification = builder.setContentIntent(contentIntent) 
        .setSmallIcon(icon).setTicker(appname).setWhen(when) 
        .setAutoCancel(true).setContentTitle(appname) 
        .setContentText(message).build(); 

      notificationManager.notify((int) when, notification); 

     } 
} 

Надеется, что это помогает.