Reputation: 146
I'm browsing the web to find out this, but I'm not lucky (or unskilled) in finding anything similar. The project is just in the "Idea" step at the moment, and the part I'm having trouble finding a way to do is sending a JSON object from a webpage to an Android application where it would be handled. The process would be as follows:
I presume there are specifics that need to be set on both sides (Webpage and Android) in order for it to work. Perhaps there's an easier (correct) way to do it, maybe even different approach in general.
Any help and advice is much appreciated.
EDIT: If it is possible I would like to avoid outside services, and would rather prefer a direct communication between the webpage and android application if it is possible.
I forgot to mention I control both the webpage and the android application
Upvotes: 1
Views: 181
Reputation: 715
I did something similar when building a OAuth2 Module for my company. So my answer in principle may relate to OAuth2 but the same concept applies.
Register an activity in the AndroidManifest.xml
This will be the activity that will be responsible for doing something with the return information.
Example
</activity>
<activity android:name=".BaseOAuth">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="oauth"
android:scheme="example" />
</intent-filter>
</activity>
In the onResume()
you can use the method getIntent().getData()
for which you can run querys' on.
Example
@Override
protected void onResume() {
super.onResume();
Uri data = getIntent().getData();
String code = data.getQueryParameter("code") == null ? "" :data.getQueryParameter("code");
}
In the above instance, I do provide a callback URL where the website redirects me too. example://oauth
Where in the OnResume I get the information returned.
Upvotes: 1
Reputation: 1314
you can use firebase cloud messaging from google firebase.google.com/docs/cloud-messaging or other service that send push message
Upvotes: 0