-1

Currently i was being able to display a push notification in my android application. And i want to add and Action to the push notification which can help me to save the notification as message.

How can i do this.

eli
  • 8,571
  • 4
  • 30
  • 40
  • 1
    Where do you have that image? In the local file? Is it downloaded from a server? – Bob Aug 15 '17 at 17:57
  • it is a downloaded image Bob – eli Aug 15 '17 at 18:01
  • the image is downloade and set it to the list view then i want onclick the particular listView send that image to the xml of DetailActivity class – eli Aug 15 '17 at 18:03
  • I would advise to store it in a local file. Then pass the file Uri to activity. And from the Activity get the Image from the local file using the Uri. – Bob Aug 15 '17 at 18:04
  • You called `getStringExtra("image")`, so what's the issue? – OneCricketeer Aug 16 '17 at 12:47

2 Answers2

0

By implementing an interface in your parent activity you can pass the image url (or object) back to your activity on image click.

public interface FragmentListener{
    void onImageClicked(String uri);
}

Implement that interface in your activity and pass it to your fragment. When you receive the onClick from the image view you can then just call ((DetailActivity)getActivity()).onImageClicked(url);

or something along those lines.

Devsil
  • 598
  • 3
  • 16
  • Why do you need the cast? The interface should be assigned from onAttach method – OneCricketeer Aug 16 '17 at 12:46
  • @cricket_007 You may not need to cast, I didnt actually run this. I just put it in there to ensure that the OP new what I was trying to get at. – Devsil Aug 16 '17 at 12:51
  • Sure did, thanks for pointing that out. I edited it just to be clear. – Devsil Aug 16 '17 at 12:55
  • Still, though. Casting shouldn't be used because it binds that one Fragment to that one Activity. Fragments are meant for reuse, and the interface is pointless since you're just calling a method of the Activity at that point. For the correct pattern, see https://stackoverflow.com/questions/24777985/how-to-implement-onfragmentinteractionlistener – OneCricketeer Aug 16 '17 at 12:58
0

You have two options

  1. if its a bitmap drawable, get the bitmap from it and save it on a disk (or internal storage)and then pass the directory location. You can also choose to pass the bitmap directly in intent but it may result in and exception as intents size should not exceed 512kb, i wouldn't take this risk

  2. if its not a bitmap, take a screen shot and then follow option 1 with the bitmap

Suhaib Roomy
  • 2,501
  • 1
  • 16
  • 22