|
1 | 1 | package com.github.gotify.service;
|
2 | 2 |
|
| 3 | +import static com.github.gotify.api.Callback.call; |
| 4 | + |
3 | 5 | import android.app.AlarmManager;
|
4 | 6 | import android.app.Notification;
|
5 | 7 | import android.app.NotificationManager;
|
|
12 | 14 | import android.net.ConnectivityManager;
|
13 | 15 | import android.net.Uri;
|
14 | 16 | import android.os.Build;
|
| 17 | +import android.os.Handler; |
15 | 18 | import android.os.IBinder;
|
| 19 | +import android.os.Looper; |
| 20 | + |
16 | 21 | import androidx.annotation.Nullable;
|
17 | 22 | import androidx.annotation.RequiresApi;
|
18 | 23 | import androidx.core.app.NotificationCompat;
|
19 | 24 | import androidx.core.content.ContextCompat;
|
| 25 | + |
20 | 26 | import com.github.gotify.MarkwonFactory;
|
21 | 27 | import com.github.gotify.MissedMessageUtil;
|
22 | 28 | import com.github.gotify.NotificationSupport;
|
|
32 | 38 | import com.github.gotify.messages.Extras;
|
33 | 39 | import com.github.gotify.messages.MessagesActivity;
|
34 | 40 | import com.github.gotify.picasso.PicassoHandler;
|
35 |
| -import io.noties.markwon.Markwon; |
| 41 | +import com.loopj.android.http.AsyncHttpClient; |
| 42 | +import com.loopj.android.http.AsyncHttpResponseHandler; |
| 43 | + |
36 | 44 | import java.util.List;
|
37 | 45 | import java.util.Map;
|
38 | 46 | import java.util.concurrent.atomic.AtomicLong;
|
39 | 47 |
|
40 |
| -import static com.github.gotify.api.Callback.call; |
| 48 | +import cz.msebera.android.httpclient.Header; |
| 49 | +import io.noties.markwon.Markwon; |
41 | 50 |
|
42 | 51 | public class WebSocketService extends Service {
|
43 | 52 |
|
@@ -323,28 +332,30 @@ private void showNotification(
|
323 | 332 | .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
|
324 | 333 | .setContentIntent(contentIntent);
|
325 | 334 |
|
326 |
| - String actionOpen = |
327 |
| - Extras.getNestedValue(String.class, extras, "client::notification", "actions", "open"); |
328 |
| - |
329 |
| - if (actionOpen != null) { |
330 |
| - Intent actionOpenIntent = new Intent(); |
331 |
| - actionOpenIntent.setAction(Intent.ACTION_VIEW); |
332 |
| - actionOpenIntent.setData(Uri.parse(actionOpen)); |
333 |
| - PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 123, actionOpenIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
334 |
| - b.addAction(new NotificationCompat.Action.Builder(null, "open", pendingIntent).build()); |
335 |
| - } |
336 |
| - |
337 |
| - String actionShare = |
338 |
| - Extras.getNestedValue(String.class, extras, "client::notification", "actions", "share"); |
339 |
| - |
340 |
| - if (actionShare != null) { |
341 |
| - Intent sendIntent = new Intent(); |
342 |
| - sendIntent.setAction(Intent.ACTION_SEND); |
343 |
| - sendIntent.putExtra(Intent.EXTRA_TEXT, actionShare); |
344 |
| - sendIntent.setType("text/plain"); |
345 |
| - Intent shareIntent = Intent.createChooser(sendIntent, null); |
346 |
| - PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 124, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
347 |
| - b.addAction(new NotificationCompat.Action.Builder(null, "share", pendingIntent).build()); |
| 335 | + String callbackUrl = |
| 336 | + Extras.getNestedValue( |
| 337 | + String.class, extras, "client::notification", "actions", "callback"); |
| 338 | + |
| 339 | + if (callbackUrl != null) { |
| 340 | + Handler callbackHandler = new Handler(Looper.getMainLooper()); |
| 341 | + Runnable callbackRunnable = new Runnable() { |
| 342 | + @Override |
| 343 | + public void run() { |
| 344 | + AsyncHttpClient client = new AsyncHttpClient(); |
| 345 | + client.post(callbackUrl, null, new AsyncHttpResponseHandler() { |
| 346 | + @Override |
| 347 | + public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { |
| 348 | + System.out.println("Callback successfully send to: " +callbackUrl); |
| 349 | + } |
| 350 | + |
| 351 | + @Override |
| 352 | + public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { |
| 353 | + System.out.println("Can't send callback to: "+callbackUrl); |
| 354 | + } |
| 355 | + }); |
| 356 | + } |
| 357 | + }; |
| 358 | + callbackHandler.post(callbackRunnable); |
348 | 359 | }
|
349 | 360 |
|
350 | 361 | CharSequence formattedMessage = message;
|
|
0 commit comments