How would you implement routing within an Activity for AppLinks? - android

So the applinks documentation states that you should specify your app's package name through the al:android:package property, and the consuming application should launch an Intent to start your app. What I feel is lacking from the documentation is a suggestion or specification on how to provide custom parameters or routing info with that Intent. It's not deep linking unless you specify some depth!
It does specify how to provide Extras through the use of the al_applink_data structure. It does not however say how the target application should provide metadata for the client to consume and send with that structure.
The only suggestion I can think of is to provide the metadata through the optional al:android:url-parameter. So for instance if I'm running a blog, I would provide the URL com.myblog://123, "123" being the ID to a blog entry.
I don't feel like this is an optimal solution. I would then have to parse the URL in order to get the argument. I feel a better solution would be to have a an applink-property named something like al:android:extras where I could give key-value pairs to consume directly. Why is it not implemented this way?
Am I doing it right if I implement metadata-passing the way I described? Is there something I'm missing with regards to the applinks spec?

The original http(s) url is given to you inside al_applink_data under the target_url key, so you can certainly pass metadata that way.
Passing it via the optional al:android:url is also OK.
Lastly, if you have cooperation from the calling app, they can certainly pass data to you via the extras blob.
The reason there's no al:android:extras is that app links was designed to be a routing protocol, and not describe semantics for your app.

Related

How to make api.ai agent learn something dynamically?

I am currently using api.ai , to create agent to perform specific tasks, but one question i don't have answer to is , can i make it learn something while chatting , mean that i speak my name is 'John Cena' and she should store it and then whenever i ask her again bot should answer me that. i know there is a way to do it by logging into api.ai web and manually add entries , but it will not help, is there any work around programmatically or automatically ? the file i've been using to practice is given in github . and here is working DEMO
You basically need for your bot to "learn" facts. There are many different ways to achieve this, but recently the most common way is to arrange knowledge into Semantic "Triples" and store the knowledge into a Graph repository (like Neo4j, Titan, Spark Graph, etc). In your example, "my name is John Cena" would translate into a Triple like ("anubava","Name","John Cena"). That way, the next time you are logged in as anubhava and ask "What is my name?", it would translate into a Graph search that will return "John Cena". A word of caution, achieving this is not trivial and would require some significant amount of fine tuning. For more info, you can check here and here.
Finally, most complete solutions (that I know of), are Server Side solutions. If you want for the whole knowledge base to reside in your mobile device, you could probably use the resources there as inspiration, and build your own Linked Data repository using an embedded database.
Hope this helps. Good luck.
To store and recall the user's name, you'll need to set up a webhook with some basic data persistence capabilities. Any database or key-value store would work fine.
Here's the breakdown:
Implement webhook fulfillment for the intent that captures the user's name. The webhook should store the name along with a unique, identifying ID that you should supply from your front-end in either the sessionId or as a context parameter in your call to /query.
Implement webhook fulfillment for the intent that reads the user's name. The webhook should look up the name by ID and return a response that tells the user their name.
The high-level docs for writing a fulfillment webhook are here:
https://docs.api.ai/docs/webhook

How to get an Album's MusicBrainz ID

I want to use the CoverArtArchiveClient to load Album Images from MusicBrainz but it requires a MusicBrainz ID (MBID). Can someone provide info on how to get the MBID for a particular Album? Code samples would be much appreciated.
Thanks
The details depend a lot on what representation you have of "a particular album".
In general MusicBrainz provides a web service (in XML and json format) where you can search for MusicBrainz entities, which will also give you the MBID.
You want to get the MBID of release entities.
Since you seem to be developing on Android in Java you might be interested in musicbrainzws2-java the Java binding of the Web Service.
There are other language bindings/libraries available for the current version (WS/2 = "NGS") of the web service and you always have the option to use the web service directly.
If you have the album available in the form of tagged audio files, then you should try to extract the tags, since sometimes MBIDs are already available in the files and you don't have to search on MusicBrainz.
EDIT:
SO how-to-get-album-image-using-musicbrainz has an answer that tells how to use the web service directly.
The MusicBrainz web service can also return links/urls to coverart directly (as described in that answer). So you save another call to the CoverArtArchive.

How to use Tmdb API or any other API

i am a newbie android coder.
i am writing a practicing app to search Movie name. I have made XML and java which has a textbox for user to type movies name, but i don't know how to search this over internet!
as i know i have to use IMDb or TMDb API, but i have no idea how to use it! i found this site :
http://www.javacodegeeks.com/2010/10/android-full-app-part-2-using-http-api.html
but there is no explanation for codes. and also i didn't found any other learning.
can somebody please write a full explanation for how to use IMDb or TMDb API for newbie?
it would be a great help to new coders like me! :)
you are most likely going to interact with these api using HttpClient. Go thru those examples first, like pulling in twitter feeds etc. Then you will be ready for the specifics of IMDb. So you are going to have to
1) Determine the base request url. Maybe it is imdb.com/api (it will be in the documentation).
2) you might need to sign up for a key which you will pass over as a parameter. (also in the documentation)
3) read the documentation to determine if you are going to use get/post since it effects how you encode the parameters. One of those parameters might be the key or you might not need a key.
4) In general you should try first in browser client before writing code, just to see what is returned. Then do the same in your code before processing.
5) all http clients are much the same, but determine what you are getting back. Is is JSON, use simple_json to parse. Is it XML, then probably use a SAXParser to handle what is returned. If you have specific questions please post them. The best we can do is give you sort of an algorithm like this as to how you go about it.
Thats really all there is to it. Just make sure you know the right url, if there is a key, if the communication is via get or post, if they are using REST you will encode url without parameters usually. Then its just a matter of parsing what you get back.
The real answer is take it one step at a time. At each step, ask if you have questions. The truth is unless we have used a particular protocol no one knows up front. Trust me, just take it one step at a time, and you will be able to handle any http api.

Creating Intents with putExtra

I have been creating Intents using putExtra() for quite a while now and just read in the Android documentation that I should be prefixing the 'name' with the package name. So, instead of 'putExtra( "ButtonText", "Ok")' it should be more like 'putExtra( "com.mycompany.myapplication.ButtonText", "Ok" ).
Is this really necessary? (seems to be OK without it).
If it is necessary what is the advantage?
Also, is the package name the callers or the one being called? If it is the callers the 'called Activity' has to know about the callers name which wouldn't be very generic.
Thanks
Is this really necessary? (seems to be OK without it).
No, it isn't necessary for a completely stand-alone app but may be considered to be good practice anyway.
It is more important in apps which are publicly available so they can interact but maintain some way of uniquely identifying themselves and the data they're exchanging. As for which package name is used will depend on the context.
To give an abstract example...
Company A produces an app which can provide some sort of data processing which apps produced by Company B and Company C can use. The 'action' for the intent will be named relevant to Company A but the data passed into it by the two 'client' apps will be named relevant to the client apps companies. Example...
AppA's docs...
To request data processing use:
com.companyA.intent.action.PROCESS_DATA
Pass data with the above intent as an extra named:
<your package name>.SOME_DATA
Now when the relevant component of AppA is called with the above, it will check that there's an 'extra' with a name which ends with .SOME_DATA but it will also be able to maintain that data separately from other data provided by other apps due to the unique prefix. So...
Company B code
Intent i = new Intent(com.companyA.intent.action.PROCESS_DATA);
i.putExtra(com.companyB.SomeApp.SOME_DATA, data);
Company C code
Intent i = new Intent(com.companyA.intent.action.PROCESS_DATA);
i.putExtra(com.companyC.SomeOtherApp.SOME_DATA, data);
OK, possibly not one of my better examples but what it comes down to is it's important to see how the Android environment is very much about different application components being able to use each other, pass data and for the source of that data to be uniquely identifiable.
It sounds more like a "best practices" thing than an actual requirement. The benefit you get here is if you stuff a lot of things in generic intents that are handled by several activities spanning several applications, then you're being more specific about the data in your Intent. If you're using these intents only internally in your application and only your own activities are handling them, you're fine the way you are.
I think this is a GREAT idea IF you are wrapping your extended data into a serializable class say com.mycompany.myapp.MyAppData and sending it as:
intent.putExtra("com.mycompany.myapp.MyAppData",myAppData); //==> out
and retrieving it as:
MyAppData myAppData= (com.mycompany.myapp.MyAppData)intent.getSerializableExtra("com.mycompany.myapp.MyAppData",myAppData; // <== in
JAL

Intent Filter on Android

I am reading the intent filter of the android, and having a few question need to ask.
Do they match the filter within the same application or all of the applications?
The scheme within the data tag, I have looked on the documentation on the android sdk website but no idea what it mean. It say scheme://host:port/path or pathPrefix or pathPattern
What is the host port and path .... What does the path relate to?
1) Depends on the type of intent that was requested. See implicit vs explicit intents in the "Intent resolution" section of the docs:
http://developer.android.com/guide/topics/intents/intents-filters.html
If you name the component exactly then you know which activity will launch. Other intents name a generic action and can be matched by multiple activities. The user gets a menu asking which app they want to use to complete the action normally. For instance download the Firefox app from the Marketplace and click on a link in an email, you'll get a prompt asking if you want to use the Browser or Firefox to open the URL.
2) That's for intercepting a custom URL scheme or overlaying HTTP requests. Sounds like that not something you're interested in doing, you can safely ignore it unless you need to use it. If you do want more info about it there's a question with some good answers already:
Launch custom android application from android browser
1) see #mikerowehl answer
2) data is referenced through Uniform Resource Indentifiers (URI's). In Android, scheme could be http, tel, file, content (don't know about others) and by specifying a certain scheme in a filter you're saying that your component can handle data provided that way.
host+port=authority. In case of a data whose scheme is http, host will of course be something like stackoverflow.com, port will probably be left unspecified (if you're accessing a proxy it could be 8080). In case of a content provider, the authority is by convention "the fully-qualified class name of the content provider (made lowercase)", without a port.
This should be the general idea. Documentation in this field is pretty scattered but you should be able to find information on a particular task (say opening email attachments) when you'll need.

Categories

Resources