Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 3    Views: 91

immacul8 apps
Aspiring developer
Profile
Posts: 58
Reg: Sep 10, 2012
adelaide
580
10/02/16 01:54 AM (8 years ago)

Android - Trying to change BT_screen_map call out Dialog icon to image loaded from URL

I am currently trying to change the icon in the call out Dialog in BT_screen_map plugin to be an image of the location loaded from a URL. Too many locations to store all images local. Its simple to change the icon from local file but I'm stumped on loading one from URL. Or maybe the image I'm trying to load can't be used in the Dialog... <img src="http://pheds.com.au/example1.png"> - Change blue icon in dialog box I've added a new item to my Json file "locationImage" in BT_screen_Map.java before "public void handleMarkerClick(final int markerIndex) {" I've put public static Drawable LoadImageFromWeb(String url) { try { BT_debugger.showIt(url); InputStream is = (InputStream) new URL(url).getContent(); Drawable d = Drawable.createFromStream(is, "src name"); return d; } catch (Exception e) { return null; } } and in public void handleMarkerClick(final int markerIndex) { ... ..... calloutTapChoice = BT_strings.getJsonPropertyValue(tappedItem.getJsonObject(), "calloutTapChoice", ""); String pinColor = BT_strings.getJsonPropertyValue(tappedItem.getJsonObject(), "pinColor", "red"); I've added String locationImage = BT_strings.getJsonPropertyValue(tappedItem.getJsonObject(), "locationImage", ""); and changed "pinGraphic = getResources().getDrawable(R.drawable.bt_screen_map_marker_red);" to "pinGraphic = LoadImageFromWeb(locationImage);" App runs in emulator, plugin loads, locations load, click marker dialog opens and no icon No error in log. LoadImageFromWeb is called and "BT_debugger.showIt(url);" returns the correct url Then seems to stop at "InputStream is = (InputStream) new URL(url).getContent();" Any ideas??
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
10/02/16 04:40 PM (8 years ago)
NSURL *url = [NSURL URLWithString:@"https://www.yourserver.com/path/to/image.png"]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *img = [[UIImage alloc] initWithData:data]; Cheers! -- Smug
 
immacul8 apps
Aspiring developer
Profile
Posts: 58
Reg: Sep 10, 2012
adelaide
580
like
10/02/16 04:55 PM (8 years ago)
Im currently working on Android Smug. . but will keep that in mind for iOs version any ideas for android? ;)
 
immacul8 apps
Aspiring developer
Profile
Posts: 58
Reg: Sep 10, 2012
adelaide
580
like
10/02/16 05:01 PM (8 years ago)
Ive worked out its due to android.os.NetworkOnMainThreadException cause of the way android now handles network requests. I need to make LoadImageFromWeb a class that extends AsyncTask< and then perform doInBackground(String... url) Am currently in the process of trying to get this working but am stuck with handling the Async as a Drawable.. .
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.