Push send
This commit is contained in:
parent
42ffa7cadb
commit
510bfe4087
@ -47,6 +47,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import at.smartshopper.smartshopper.R;
|
import at.smartshopper.smartshopper.R;
|
||||||
import at.smartshopper.smartshopper.db.Database;
|
import at.smartshopper.smartshopper.db.Database;
|
||||||
|
import at.smartshopper.smartshopper.messaging.MyFirebaseSender;
|
||||||
import at.smartshopper.smartshopper.shoppinglist.Shoppinglist;
|
import at.smartshopper.smartshopper.shoppinglist.Shoppinglist;
|
||||||
import at.smartshopper.smartshopper.shoppinglist.ShoppinglistAdapter;
|
import at.smartshopper.smartshopper.shoppinglist.ShoppinglistAdapter;
|
||||||
import at.smartshopper.smartshopper.shoppinglist.ShoppinglistSharedAdapter;
|
import at.smartshopper.smartshopper.shoppinglist.ShoppinglistSharedAdapter;
|
||||||
@ -783,6 +784,13 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte
|
|||||||
@Override
|
@Override
|
||||||
public void sharedOnChangeItemClick(String sl_id, View v) {
|
public void sharedOnChangeItemClick(String sl_id, View v) {
|
||||||
onChangeItemClickContainer(sl_id, v);
|
onChangeItemClickContainer(sl_id, v);
|
||||||
|
try {
|
||||||
|
new MyFirebaseSender(db.getMembers(sl_id)).sendMessage("Eine ihrer Shoppinglisten wurde geändert", "MY_ACTION");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,7 +26,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(RemoteMessage remoteMessage) {
|
public void onMessageReceived(RemoteMessage remoteMessage) {
|
||||||
super.onMessageReceived(remoteMessage);
|
sendNotification(remoteMessage.getNotification().getBody());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
package at.smartshopper.smartshopper.messaging;
|
||||||
|
|
||||||
|
import com.google.firebase.messaging.FirebaseMessaging;
|
||||||
|
import com.google.firebase.messaging.RemoteMessage;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import at.smartshopper.smartshopper.R;
|
||||||
|
import at.smartshopper.smartshopper.shoppinglist.Member;
|
||||||
|
|
||||||
|
public class MyFirebaseSender {
|
||||||
|
|
||||||
|
private List<String> messageIds;
|
||||||
|
|
||||||
|
public MyFirebaseSender(List<Member> members) {
|
||||||
|
ArrayList<String> tmp = new ArrayList<>();
|
||||||
|
for (Member m : members) {
|
||||||
|
tmp.add(m.getMsid());
|
||||||
|
}
|
||||||
|
messageIds = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sendet die Firebase Messages zum server
|
||||||
|
*
|
||||||
|
* @param message Push Nachricht
|
||||||
|
* @param action Push action
|
||||||
|
*/
|
||||||
|
public void sendMessage(String message, String action) {
|
||||||
|
FirebaseMessaging firebaseMessaging = FirebaseMessaging.getInstance();
|
||||||
|
for (int i = 0; messageIds.size() > i; i++) {
|
||||||
|
|
||||||
|
firebaseMessaging.send(new RemoteMessage.Builder(R.string.firebase_sender_id + "@fcm.googleapis.com/fcm/send")
|
||||||
|
.setMessageId(messageIds.get(i))
|
||||||
|
.addData("my_message", message)
|
||||||
|
.addData("my_action", action)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,4 +4,5 @@
|
|||||||
<string name="title_activity_shoppinglist_detail">ShoppinglistDetail</string>
|
<string name="title_activity_shoppinglist_detail">ShoppinglistDetail</string>
|
||||||
<string name="title_activity_shoppinglist_details">ShoppinglistDetails</string>
|
<string name="title_activity_shoppinglist_details">ShoppinglistDetails</string>
|
||||||
<string name="title_activity_item_list">ItemListActivity</string>
|
<string name="title_activity_item_list">ItemListActivity</string>
|
||||||
|
<string name="firebase_sender_id">221332577314</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user