-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.java
63 lines (38 loc) · 1.72 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//packge name
public class ActivityDash extends AppCompatActivity {
String usertoken;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityDashBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
FirebaseMessaging.getInstance().subscribeToTopic("all");
// fcm settings for perticular user
FirebaseInstanceId.getInstance().getInstanceId()
.addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (task.isSuccessful()) {
usertoken = Objects.requireNonNull(task.getResult()).getToken();
Log.d("toooo","token= "+usertoken);
}
}
});
}
// call this for send notification to all
public void noti()
{
FcmNotificationsSender notificationsSender = new
FcmNotificationsSender("/topics/all" ,"Tilte","admin app",
getApplicationContext(),ActivityDash.this);
notificationsSender.SendNotifications();
}
// call this for send notification to specified user
public void noti2()
{
FcmNotificationsSender notificationsSender = new
FcmNotificationsSender(usertoken,"Tilte","admin app",
getApplicationContext(),ActivityDash.this);
notificationsSender.SendNotifications();
}
}