How to identify that user has not deleted the app? - javascript

I have developed the Phonegap App.
I want to identify that app is installed in user mobile.
When user install app, h/she will register with our API server to use the app. First screen of APP is registration form.
We have maintained the UNIQUE user id so that we can identify the device and user.
I have used the push notification in APP.
Now I want to send the request to server from mobile that application is in mobile.
I want to code such that mobile will send the request to API server after specific interval of time. Time will be in days.
And the process to send request to server must run in background.
Can anyone help regarding this??

If user deletes your app,how can you send request from mobile to your server? I think it'll be deleted with total instances so that there won't be any code with whom you can send request. If you found any way to send request after deletion, here is the code for checking if your application exists or not. It's native coede.
protected boolean isAppInstalled(String packageName) {
Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
if (mIntent != null) {
return true;
}
else {
return false;
}
}
packageName is your app package name.

Related

Browser Notification Push Service: How to specify push server?

I'm trying to set up push notifications for a browser web app.
I found the following code can be used to subscribe to a push server. Running a simple push server locally seems to work fine, but
Q: I was wondering how I would specify the push server if it wasn't local?
I mean, how would the browser know where to subscribe to just by looking at the public key of the server?
function createNotificationSubscription(pushServerPublicKey) {
return navigator.serviceWorker.ready.then(
(serviceWorker) => {
return serviceWorker.pushManager
.subscribe({
userVisibleOnly: true,
applicationServerKey: pushServerPublicKey
})
.then((subscription) => {
console.log("✅ User is subscribed.", subscription);
return subscription;
});
}
);
}
References:
https://developer.mozilla.org/en-US/docs/Web/API/PushManager/subscribe
how do I specify the push server [...]?
You don't.
if it wasn't local?
There is a misunderstanding.
The push server will always be a fixed server given by the browser vendor.
It basically works like this:
You subscribe()
This request goes to the notification server of the browser vendor (mozilla, google, ...).
That server will create a so called push endpoint - just a fancy word for URL. This URL serves as a mailbox: If someone sends a message to it, the push server (still being the server of the browser vendor) will forward it to the browser (client).
The server will return the push endpoint and some other information as a result of your initial subscribe().
Currently only the push server and your web app know about the push endpoint....
So your web app needs to the whole result of subscribe to the application server (which is your server).
Now your server is able to use that information to send messages to the push server. The push server will then forward the message to the client.
Here's also a flow chart depicting the flow with a little more detail in regard of the different players:
Push service: Service running on the browser vendor's server
Subscription information: URL of the push endpoint along with some keys.

How can i implement GCM in meteor web application

I want to Send push notifications from meteor website to android application using Google cloud messaging.
The way I've done it is to use the package raix:push.
To do this, first install the package, then set up a config.push.json file in your root directory. This file contains the settings for the push notifications. The most basic file you can have that allows you to use Google cloud messaging is just:
{
"gcm":{
"apiKey":"yourApiKey",
"projectNumber": 000000000
}
}
Then you can send a push notification by calling a meteor method:
Meteor.methods({
"sendPush": function(title, text, userId){
Push.send({
from: 'yourName',
title: title,
text: text,
query:{userId: userId}
});
}
});
and also calling:
Push.allow({
// Change this to determine whether the user with id userId can send
// the notification
send: function(userId, notification) {
return true; // Allow all users to send
}
});
on the server.
The above method would send a push notification to a user with _id equal to userId. You can make the query more complicated to send multiple notifications at once, just keep in mind that the field with the user's id is called userId, since this package creates a new collection to emit notifications.
This package is documented quite well: https://github.com/raix/push. Just follow the instructions for android, and take a look at the simple example.
If you don't have an api key or project number, you can follow the instructions in the documentation to set up Google cloud messaging.

SignalR Content Specific Notifications

I am using SignalR for notifications in my web site but i couldn't find a way to send notifications according to the page/content.
Let me explain in details.
Assume that, there is a page for showing a record from database (for example a blog post).
So there is only one page for showing posts as it should be.
And every post has a like counter which i want to update via signalr notifications, if another user clicks like button. Until here, it is very easy to accomplish.
This page contains a javascript code block like below
var notify = $.connection.notificationHub;
notify.client.updatePostLikeCount = function (likeCount) {
$("#likeCount").text(likeCount);
};
And this function triggered from server-side like below (it is in another class instead of Hub class)
var context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
context.Clients.User(user.Id).updatePostLikeCount(likeCount);
But a user might open more than one post; so if a notification is sent from server-side all opened tabs receive this notification and update its counter.
I looked for .Caller method but it is not available in IHubContext interface which GetHubContext() returns and couldn't find another way.
To summarize, i want to send notifications to users who had opened the post which user liked.
EDIT: After sending question i got an idea. Continue sending notification as being and filtering according to the content at client side. It is not very good but i think it will work with charms.

GCM and server side related issue

I'm currently trying out GCM on android with the DemoActivity project that I downloaded from android SDK. There are a couples of question regarding this whole GCM stuff. Correct me if I'm wrong.
Based on my understanding, what we needed to register the android device for GCM is just Sender_ID and Server_URL? Server_URL is based on the URL of my 3rd Party Application Server for example http://localhost:8080/gcm_test. As for Sender_ID is basically Google API's Project ID.
Do I need to send the registration ID from the android device to the server side and store it in server side database or something like that?
In order to send message from server to the android device, we needed API key and the android Registration ID?
How to configure on the server side in order to send message?
1)Right
2)Yes.You need that whenever you need to send a Push Notification to a particular device.The server identifies this device using a registeration id.
3)You need the Google App Id you got when you created the project and the registration Id you saved on the backed.
4)For ASP.NET look at this.
string GoogleAppID = "google application id";
var SENDER_ID = "9999999999";
//......
//......
AndroidGCMPushNotification apnGCM = new AndroidGCMPushNotification();
string strResponse =
apnGCM.SendNotification(devRegId,
"Test Push Notification message ");

Android app login

There are some apps that require login. May I know how the app manage user session on android? For example, once the user has sign in to the app, the next time user start the app, it will straight go to the home page instead of the login page. While if user start the app for the first time or before login, the app will start with the login page. Can phonegap handle this? Thank you.
Depending on which version of Android you are targeting and which version of PhoneGap you are running, you should use one of the built-in offline storage mechanisms available in the browser. These include localStorage and WebKitSQLite.
There is also a fantastic open source library that you can use that abstracts any specific offline storage mechanism and allows for swappable underlying storage adapters, and provides a single unified key/value interface. The library is called Lawnchair - check it out!
So on-load, you would instantiate Lawnchair and see if your saved user parameters exist:
function onLoad() {
myStore = new Lawnchair();
myStore.get('login', function(i) {
if (i == null) {
// user did not login before, no saved credentials.
} else {
// user DID login, we can now auto-login for the user.
}
});
}
Additionally, following a successful manual login, you can save the credentials to Lawnchair so that they will be available next time your PhoneGap app loads and checks for their existence:
function login(username, password) {
/*
* Do the login stuff here
*/
if (/* login was successful */) {
myStore.save({key:'login',value:{username:username, password:password}});
} else {
alert('Could not log you in!');
}
}
The most important bit between the two chunks of code you see here is the first parameter to the get() function, and the key property to the object passed into the save() function. Both of these need to match to retrieve the same object.
Hope that helps!
You can store it in the prefs. Here is how
SharedPreferences settings = .getSharedPreferences("some_key, MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putString("token", "123456");
editor.commit();
Next time the app starts up you can check to see if this exists. Hope it helps
Don't know what is phonegap, but I think usually apps simply store the login somewhere in shared preferences. So, all you need is to check on startup if there is some particular preference. If there isn't any, then the login page should be shown.

Categories