来自edittext字段的通知contenttext

时间:2013-11-25 08:38:17

标签: android notifications android-edittext charsequence

 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。 我试了几个例子,但没有运气。

4 个答案:

答案 0 :(得分:2)

你必须改变这个:

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

并在此之后设置:

.setContentText(name)

答案 1 :(得分:0)

试试这种方式

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

答案 2 :(得分:0)

这样做:

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

检查我的问题here

答案 3 :(得分: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);

        }
}

希望这有帮助。