So what i partially achieved was to set an app that gets JSON text from a weather website of this form:
{
"base": "stations",
"clouds": {
"all": 20
},
"cod": 200,
"coord": {
"lat": 40.94,
"lon": 24.41
},
"dt": 1513711200,
"id": 735861,
"main": {
"humidity": 100,
"pressure": 1027,
"temp": 274.15,
"temp_max": 274.15,
"temp_min": 274.15
},
"name": "Kavala",
"sys": {
"country": "GR",
"id": 5684,
"message": 0.0039,
"sunrise": 1513662178,
"sunset": 1513695412,
"type": 1
},
"visibility": 10000,
"weather": [
{
"description": "few clouds",
"icon": "02n",
"id": 801,
"main": "Clouds"
}
],
"wind": {
"deg": 51.0029,
"speed": 3.07}}
decodes it into a list and store the results in some labelboxes in the app.The values i want to use from this JSON are:
("main": {"temp":}, "weather": {"main":}, "main": {"humidity":}, "wind":{"speed}".
I have managed to that quite efficiently using the integrated json decode function and indexing from App Inventor.
Photo of Block Code:
(SCREEN RED POINTER is supposed to be "weather": {"main":} value)
My problem is that for some cities(the app searches for data from the city name the user enters) the indexes for "weather": {"main":} and "wind":{"speed}" are different.Is there any way i can set up a check routine for this problem?
For example, for "weather": {"main":} the usual indexing as it can be seen in my code(image) is 11 2 1 4 2 of the created list.For the cities that have different index and respond with an error i think its 10 2 1 4 2.
OBJECTIVE:So what i want to do is find a way to check if the element on the 11 2 1 4 2 exists so i can use it,else look for the element with indexes 10 2 1 4 2 to use.
UPDATE:OBJECTIVE COMPLETE DESPITE THE JSON deformity 2 dependent look up in pairs fixed the issue!
Don't use nested select list item blocks as you are doing currently...
The better approach is to use the loopup in pairs block and the sequence of the data will not be important anymore...
How does the lookup in pairs block work?
Further links
JSON and list of lists: example1 and example2
Easy to decode large information with JSON format by Carlos
A general purpose JSON browser routine by ABG
JSON Tools Extension by LukeGackle
Related
I am an android Novice.
I am using the Universal Android Media Player sample code as basis of another app but I cannot figure out how to update the default music JSON.
The code is in Kotlin. Any help in figuring out where the JSON is and how to update it will be much appreciated?
The UAMP sample code uses an external JSON file with this format:
{
"music": [
{
"id": "wake_up_01",
"title": "Intro - The Way Of Waking Up (feat. Alan Watts)",
"album": "Wake Up",
"artist": "The Kyoto Connection",
"genre": "Electronic",
"source": "https://storage.googleapis.com/uamp/The_Kyoto_Connection_-_Wake_Up/01_-_Intro_-_The_Way_Of_Waking_Up_feat_Alan_Watts.mp3",
"image": "https://storage.googleapis.com/uamp/The_Kyoto_Connection_-_Wake_Up/art.jpg",
"trackNumber": 1,
"totalTrackCount": 13,
"duration": 90,
"site": "http://freemusicarchive.org/music/The_Kyoto_Connection/Wake_Up_1957/"
},
...
]
}
This variable is declared inside the MusicService.kt
private val remoteJsonSource: Uri = Uri.parse("https://storage.googleapis.com/uamp/catalog.json")
I have a source for tiles as an url and want to add these to my map.
I am able to do this with Google Map and OSMDroid, but I do not know how to figure it out using Mapbox.
My url has the format "http...mysource..x=..y=..z=.."
I have seen a solution for web, but I do not find such an approach for mobile.
I assume you have a URL for a tile server such as http://server/tiles/{z}/{x}/{y}.png If so, please update your question.
Please see this Mapbox example, https://www.mapbox.com/android-sdk/examples/custom-raster/ to add in a custom Mapbox Style. Note the parameter for setStyleUrl. Open up that json file and inspect it.
mapView.setStyleUrl("https://www.mapbox.com/android-sdk/files/mapbox-raster-v8.json");
You will then need to create two JSON files. See this project (which is for iOS, but the JSON files are identical for Android, Web, and iOS.).
tile.json sample
{
"name": "geography-class",
"version": "1.0.0",
"description": "",
"type": "overlay",
"format": "png",
"minzoom": 0,
"maxzoom": 8,
"bounds": [-117.30596604, 32.78617375, -117.21820077, 32.88817706],
"scale": "1",
"profile": "mercator",
"tiles": ["http://server/tiles/{z}/{x}/{y}.png"],
"tilejson": "2.0.0",
"scheme": "xyz"
}
Mapbox Style JSON, put this in the parameter for setStyleUrl()
{
"version": 8,
"sources": {
"yourTileLayer": {
"url": "http://server/tiles/tile.json",
"type": "raster",
"tiles": [
"http://server/tiles/{z}/{x}/{y}.png"
],
"tileSize": 256
}
},
"layers": [
{
"id": "yourTileLayer",
"type": "raster",
"source": "yourTileLayer"
}
]
}
I've just recently stumbled over Brillo on Google's source code website. On it, I've found several files with the extension bpt. These are JSON files that appear to describe partitions on devices. Here are the contents of the base file:
{
"settings": {
"disk_size": "4 GiB"
},
"partitions": [
{
"ab": true,
"label": "boot",
"size": "32 MiB",
"guid": "auto",
"type_guid": "brillo_boot"
},
{
"ab": true,
"label": "system",
"size": "512 MiB",
"guid": "auto",
"type_guid": "brillo_system"
},
{
"ab": true,
"label": "odm",
"size": "512 MiB",
"guid": "auto",
"type_guid": "brillo_odm"
},
{
"label": "misc",
"size": "1 MiB",
"type_guid": "brillo_misc"
},
{
"label": "userdata",
"grow": true,
"guid": "auto",
"type_guid": "brillo_userdata"
}
]
}
I can't find any documentation on this. Is it a new partition scheme (e.g., MBR, GPT, APM, Tegra PT, MTD's command line partition table parsing, etc.)?
JSON files with .bpt extensions are consumed by bpttool - A tool for partitioning disk images for Brillo and Android.
This is open sourced and is hosted at https://android.googlesource.com/platform/system/tools/bpt/+/master/
Partitioning directives are expressed in the .bpt JSON file.
Looking at the history of the repository (relatively new, only 4 months old). This was first introduced for Brillo and will probably end up in Android versions soon (In Nougat perhaps?). This may be a replacement for the GPT partitioning scheme or a derivative of it.
I'm trying to create a tourism app for Android.
I need the user be guided by voice. I've been looking at the googlemaps Android API but there's nothing about voice directions.
Do you know any workaround for this? Is there any other API/SDK that I could use to implement this?
Thanks in advance.
That's a very cool idea. However, I do not know if you're ready to reinvent the wheel to do that. In case you are, I also have a solution but let me first introduce the way I would solve this problem:
On Android, there is the intent system which allows you to call internal apps in order to make your job easier. So why wouldn't you launch the Directions app (Google Maps with a special intent) since the user likely is familiar with the UI and probably likes it? Also, with this solution, you do not need to take care about keeping your stuff updated, you just ask the system and it'll provide the solution out of the box. And it is much much easier to proceed this way. :)
To do that, you will use plain basic URI that the system will recognise:
String address = "My Fake Address";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=" + address));
startActivity(intent);
After that, the user will be able to choose how he wants to go there and your job is done, the user is satisfied, and you did like 99% of the other apps (he has the vocal messages as well).
Then, if it is in your requirements to have it inside your app, it could be possible (based on Aster proposition) but you'll need to keep a track of the user yourself (to be able to send the good instruction at the right time). But first let's take a look at the Directions API of Google, if you correctly set up your App you should receive this kind of JSON (whole doc there):
{
"status": "OK",
"routes": [ {
"summary": "I-40 W",
"legs": [ {
"steps": [ {
"travel_mode": "DRIVING",
"start_location": {
"lat": 41.8507300,
"lng": -87.6512600
},
"end_location": {
"lat": 41.8525800,
"lng": -87.6514100
},
"polyline": {
"points": "a~l~Fjk~uOwHJy#P"
},
"duration": {
"value": 19,
"text": "1 min"
},
"html_instructions": "Head \u003cb\u003enorth\u003c/b\u003e on \u003cb\u003eS Morgan St\u003c/b\u003e toward \u003cb\u003eW Cermak Rd\u003c/b\u003e",
"distance": {
"value": 207,
"text": "0.1 mi"
}
},
...
... additional steps of this leg
...
... additional legs of this route
"duration": {
"value": 74384,
"text": "20 hours 40 mins"
},
"distance": {
"value": 2137146,
"text": "1,328 mi"
},
"start_location": {
"lat": 35.4675602,
"lng": -97.5164276
},
"end_location": {
"lat": 34.0522342,
"lng": -118.2436849
},
"start_address": "Oklahoma City, OK, USA",
"end_address": "Los Angeles, CA, USA"
} ],
"copyrights": "Map data ©2010 Google, Sanborn",
"overview_polyline": {
"points": "a~l~Fjk~uOnzh#vlbBtc~#tsE`vnApw{A`dw#~w\\|tNtqf#l{Yd_Fblh#rxo#b}#xxSfytAblk#xxaBeJxlcBb~t#zbh#jc|Bx}C`rv#rw|#rlhA~dVzeo#vrSnc}Axf]fjz#xfFbw~#dz{A~d{A|zOxbrBbdUvpo#`cFp~xBc`Hk#nurDznmFfwMbwz#bbl#lq~#loPpxq#bw_#v|{CbtY~jGqeMb{iF|n\\~mbDzeVh_Wr|Efc\\x`Ij{kE}mAb~uF{cNd}xBjp]fulBiwJpgg#|kHntyArpb#bijCk_Kv~eGyqTj_|#`uV`k|DcsNdwxAott#r}q#_gc#nu`CnvHx`k#dse#j|p#zpiAp|gEicy#`omFvaErfo#igQxnlApqGze~AsyRzrjAb__#ftyB}pIlo_BflmA~yQftNboWzoAlzp#mz`#|}_#fda#jakEitAn{fB_a]lexClshBtmqAdmY_hLxiZd~XtaBndgC"
},
"warnings": [ ],
"waypoint_order": [ 0, 1 ],
"bounds": {
"southwest": {
"lat": 34.0523600,
"lng": -118.2435600
},
"northeast": {
"lat": 41.8781100,
"lng": -87.6297900
}
}
} ]
}
So what could be possible is to take these html_instructions and to read them to the user with the Android TTS Lib when he is in a square around the start_location or the end_location. However, it can be very complicated to manage this square properly, that's why I would use the first option which is really respecting the Android Spirit.
BTW, here are the definition of these attributes:
start_location contains the latitude/longitude coordinates of the origin of this leg. Because the Directions API calculates directions between locations by using the nearest transportation option (usually a road) at the start and end points, start_location may be different than the provided origin of this leg if, for example, a road is not near the origin.
end_location contains the latitude/longitude coordinates of the given destination of this leg. Because the Directions API calculates directions between locations by using the nearest transportation option (usually a road) at the start and end points, end_location may be different than the provided destination of this leg if, for example, a road is not near the destination.
I'm thinking of using couchDB in one of my android applications. I've designed a basic application looking into couchdb tutorial. Couchbase server has been setup. When I replicate the data, I can see 3 documents per replication.
1. 78e2c7dc-da9a-42f4-95a6-03bd6cea7b6e { "_sync": { "rev":
"1-5aca82e9-e4cc-47db-9cce-fe32fea68d1c", "sequence": 1, "history":
{ "revs": [ "1-5aca82e9-e4cc-47db-9cce-fe32fea68d1c" ], "parents": [
-1 ], "bodies": [ "" ], "channels": [ null ] }, "time_saved": "2014-04-26T14:58:37.399871861+05:30" }, "check": false,
"created_at": "25-04-14", "text": "huhahhahhahah" }
Delete Edit Document
_sync:local:a7e278f189bb5954e0bae030cf2dd2b231a7318e { "_rev": "0-1", "lastSequence": "1" }
Delete Edit Document
_sync:seq 4
I need to know how to filter this meta data from getting replicated. All I need from the above data is the "check, created_at, text" attributes. I did some research. All I could found is that I've to ignore _sync properties during sync. But I could not get how to do this.