1

I am working on android. My app contains a gallery of images. Every day I need to display one image as notification. i.e when notification is clicked it should open the GALLERY image and from there all the other images will be opened while swiping.

GridView.java

gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v,
                    int position, long id) {
                intent = new Intent(First.this, Gall.class);
                intent.putExtra("pos", position);
                startActivity(intent);
            }
        });

Gall.java

int posi;

Bundle extras = getIntent().getExtras();
   if (extras != null) 
   {
     posi = extras.getString("pos");
   }

gal.setAdapter(new GallAdapter(this));
gal.setSelection(posi);

MyAlarmService:

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);

        mManager = (NotificationManager) this.getApplicationContext()
                .getSystemService(
                        this.getApplicationContext().NOTIFICATION_SERVICE);
        Intent intent1 = new Intent(this.getApplicationContext(), Gall.class);

        Notification notification = new Notification(R.drawable.icon,
                "Image of the Day!", System.currentTimeMillis());
        intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
                this.getApplicationContext(), 0, intent1,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.setLatestEventInfo(this.getApplicationContext(),
                "My Images", "Image of the Day!", pendingNotificationIntent);

        mManager.notify(0, notification);

        stopSelf();
    }

I have total 35 images. So daily at 8am one image will be displayed as notification and when the notification is clicked it should open that image and should redirect to gallery page. Now since there are 35 images I want to display one image per day.

From the above code, after 8am the notification will not come. So at that time the normal gallery class will be called from gridview and it is working fine. But when the notification comes then how can I send the position of the image to gallery class so that frst day 1st image, 2nd day second image,...upto 35. And after 35 again the position should start from 1,2,,,...

How can I do this? Please help me in this regard. Will be really thankfull

Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124
Amrutha
  • 575
  • 4
  • 9
  • 29

1 Answers1

1

You can use LocalBroadcast Manager for sending a local broadcast message containing the position. In the activity you can register your receiver to receive local broadcasts. Whenever notification occurs, you can send a local broadcast which will be received by your Activity.

The docs say:

It is a helper to register for and send broadcasts of Intents to local objects within your process. This is has a number of advantages over sending global broadcasts with sendBroadcast(Intent). One of them is that the data you are broadcasting won't leave your app, so don't need to worry about leaking private data.`

You can see here How to use it: how to use LocalBroadcastManager?. Hope it helps you.

Community
  • 1
  • 1
Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124