I'm writing Unity mobile application which uses Android native plugin. This plugin creates background location service and notifies user when he approaches specific points on map (which are architectural monuments btw).
So Service sends push notification, and when users clicks on this notification, the app should be opened from place it paused earlier.
To create this notification, I wrote next code:
Intent intent = new Intent(this, UnityPlayerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification n = new Notification.Builder(this)
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(R.drawable.app_icon)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(Notification.PRIORITY_HIGH)
.setContentIntent(pIntent)
.setAutoCancel(true).build();
mNotificationManager.notify(notificationID, n);
The trick is that Unity uses one Activity (UnityPlayerActivity
) during app lifecycle. But I must build standalone .jar
file with my service which cannot use UnityPlayerActivity
class because it don't know about that.
I can get current Activity
instance only on runtime and work with it while starting service.
Question: How can I get Activity.class
from Service while creating Intent
?
Thank you for response.
UPD: I cannot put my service into Intent
constructor. The second parameter in Intent
constructor must be Activity.Class
which should open when user clicks on notification. If I put Service.Class
there, nothing opens.
So I need to put as a second parameter UnityPlayerActivity
instance which I can get only on runtime, but don't know how to import it into service.