如何从列表视图中获取项目并在推送通知中显示

时间:2014-03-11 09:59:52

标签: android listview

我想从listview获取项目并在推送通知中显示。我使用了服务, 我必须将参数从ListActivity.class传递给ActuelNotif.class ..我必须将参数从Activity类传递给Service类。

ListActivity.class:

    AlarmManager alarmManager = (AlarmManager) this
        .getSystemService(this.ALARM_SERVICE);
    long when = System.currentTimeMillis(); // notification time
    Intent intent = new Intent(this, ActualNotif.class);
    PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent,
        0);
    alarmManager.setRepeating(AlarmManager.RTC, when,
        (AlarmManager.INTERVAL_FIFTEEN_MINUTES / 3), pendingIntent);
    Bundle bundle = new Bundle();
    bundle.putSerializable("feed", feed);

    intent.putExtras(bundle);
@Override
        public View getView(int position, View convertView, ViewGroup parent) {

            // Inflate the item layout and set the views
            View listItem = convertView;
            int pos = position;
            if (listItem == null) {
                listItem = layoutInflater.inflate(R.layout.list_item, null);
            }

            // Initialize the views in the layout
            ImageView iv = (ImageView) listItem.findViewById(R.id.thumb);
            // set the ImageView opacity to 50%
            TextView tvTitle = (TextView) listItem.findViewById(R.id.title);
            TextView tvDate = (TextView) listItem.findViewById(R.id.date);

            // Set the views in the layout
            imageLoader.DisplayImage(feed.getItem(pos).getImage(), iv);
            tvTitle.setText(feed.getItem(pos).getTitle());
            tvDate.setText(feed.getItem(pos).getDate());

            return listItem;
        }

ActualNotif.class:

 @Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ACTION);
registerReceiver(notifyServiceReceiver, intentFilter);

// Send Notification
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
myNotification = new Notification(R.drawable.ic_launcher,
    "Notification!", System.currentTimeMillis());
Context context = getApplicationContext();
String notificationTitle = "Exercise of Notification!";
String notificationText = "Informaticen ";
RSSFeed feed = (RSSFeed) intent.getExtras().get("feed");

Intent i = new Intent(ActualNotif.this, DetailActivity.class);

i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

PendingIntent pendingIntent = PendingIntent.getActivity(
    getBaseContext(), 0, i, Intent.FLAG_ACTIVITY_NEW_TASK);

myNotification.defaults |= Notification.DEFAULT_SOUND;
myNotification.flags |= Notification.FLAG_AUTO_CANCEL;
myNotification.setLatestEventInfo(context, notificationTitle,
    notificationText, pendingIntent);
notificationManager.notify(MY_NOTIFICATION_ID, myNotification);

return super.onStartCommand(intent, flags, startId);

0 个答案:

没有答案
相关问题