android - Changing Imageviewresource in remoteview notification -
i displaying notification music player inside service class buttons , textview. text getting updated whenever song changes need change imageviewresource on click of play button should change pause once music stopped. issue facing when textview text changes whole notification view refreshes 1 sec , text changes. how stop refresh of whole view?this code tried far:
service class:
@override public int onstartcommand(intent intent,int flags,int startid) { if(intent!=null) { string action = intent.getaction(); if(!textutils.isempty(action)) { if(action.equals(action_pause)) { remoteview.setimageviewresource(r.id.btnplay_notif,r.drawable.btn_pause); //changing imageview frm play pause appwidgetmanager manager = appwidgetmanager.getinstance(getapplicationcontext()); manager.updateappwidget(r.id.btnplay_notif, remoteview); // app widget id given correct? pauseplayer(); }} return 1; } @override public void onprepared(mediaplayer mp) { mp.start; context context = getapplicationcontext(); remoteview = new remoteviews(context.getpackagename(), r.layout.notification); remoteview.settextviewtext(r.id.tv_song_title_notif, songtitle); }
you must access imageview view through remoteview , set image resource/bitmap. if need donwload image before, can use library universal image loader bitmap , url.
remoteview.setimageviewresource(r.id.yourimageview, r.drawable.yourresource); nmanager.notify(notification_panel_id, notification);
or
imageloader.loadimage(imageurl, options, new imageloadinglistener() { @override public void onloadingstarted(string arg0, view arg1) { } @override public void onloadingfailed(string arg0, view arg1, failreason arg2) { } @override public void onloadingcomplete(string text, view view, bitmap bitmap) { remoteview.setimageviewbitmap(r.id.yourimageview, bitmap); nmanager.notify(notification_panel_id, notification); } @override public void onloadingcancelled(string arg0, view arg1) { } });
Comments
Post a Comment