开发者

EditText in a BroadcastReceiver

I'm using a BroadcastReceiver to receive a Notification at a given time. Now I trying to get the Input from a EditText into that Status Bar Notification. I tried it now with a LayoutInflater but I just can't get it to work.

public class AlarmBroadcastReceiver extends BroadcastReceiver {

public void onReceive(Context context, Intent intent) {
    notificationStatus(context);
}

private void notificationStatus(Context context) {
    final NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    LayoutInflater mInflater = LayoutInflater.from(context);
    View myView = mInflater.inflate(R.layout.main, null);

    EditText etxt_title = (EditText) myView.findViewB开发者_如何学JAVAyId(R.id.etxt_title);
    String n_title = etxt_title.getText().toString();

    EditText etxt_message = (EditText) myView.findViewById(R.id.etxt_message);
    String n_message = etxt_message.getText().toString();

    final long when = System.currentTimeMillis();
    final int icon = R.drawable.notification_icon;
    final Notification notification = new Notification(icon, n_title + " - " + n_message, when);
    final Intent notificationIntent = new Intent(context
            .getApplicationContext(), Main.class);
    final PendingIntent contentIntent = PendingIntent.getActivity(context
            .getApplicationContext(), 0, notificationIntent, 0);

    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.setLatestEventInfo(context, n_title, n_message,
            contentIntent);
    mNotificationManager.notify(1, notification);
}}

Do you have any idea why it doesn't work like this? The output I'm getting is just empty, no error.


I'm using a BroadcastReceiver to receive a Notification at a given time.

That sentence does not make any sense. BroadcastReceivers do not "receive a Notification" at all.

Now I trying to get the Input from a EditText into that Status Bar Notification.

Your EditText needs to be in an activity. You do not have an activity.

I tried it now with a LayoutInflater but I just can't get it to work.

First, a BroadcastReceiver has no user interface.

Second, just because you inflate a layout with LayoutInflater, that does not mean that the layout actually appears on the screen. For that, you need an activity.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜