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

4

4 回答 4

2

你必须改变这个:

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

并在此之后设置:

.setContentText(name)
于 2013-11-25T08:41:07.947 回答
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);

        }
}

希望这可以帮助。

于 2013-11-25T09:18:57.207 回答
0

试试这个方法

setContentText(message.getText().toString())
于 2013-11-25T08:40:49.090 回答
0

这样做:

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

在这里检查我的问题。

于 2013-11-25T08:50:51.977 回答