I am using cordova to create an android application. Since the android service is killing, I associate the service with a notification to avoid killing the service.
Here is my method of how I associate a service with a notification
@Override public int onStartCommand(Intent intent, int flags, int startId) { context = this.getApplicationContext(); notifyService(); return START_NOT_STICKY; } private void notifyService() { String package_name = this.getApplication().getPackageName(); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Bitmap icon = BitmapFactory.decodeResource(getResources(), this.getApplication().getResources().getIdentifier("icon", "drawable-hdpi", package_name)); Notification notification = new NotificationCompat.Builder(this) .setContentTitle("Smart Home") .setContentText("Smart Home running in background") .setSmallIcon(this.getApplication().getResources().getIdentifier("icon", "drawable-hdpi", package_name)) .setContentIntent(pendingIntent) .setOngoing(true) .build(); startForeground(notificationId, notification); }
Here is the conclusion
A notification is generated, but the notification title is not the same as me. In addition, when I click this notification, it goes to the activity of the application information. But I want to move on to my main activity.
Has anyone encountered the same problem? Or does my code need any changes for the cordova?
source share