service
サーバーとの通信に使用するアプリケーションを作成しました。サービスからの応答は、UI の更新に使用されます。私はそうするために使用BroadcastReciever
しています。戻るボタンを押すと、サービスはバックグラウンドで継続的に実行されます(メインスレッドでサービスを実行していません)。戻るボタンでアプリを閉じます。ここで、応答についてサービスからユーザーに通知を送信したいと考えています。
助言がありますか?。
service
サーバーとの通信に使用するアプリケーションを作成しました。サービスからの応答は、UI の更新に使用されます。私はそうするために使用BroadcastReciever
しています。戻るボタンを押すと、サービスはバックグラウンドで継続的に実行されます(メインスレッドでサービスを実行していません)。戻るボタンでアプリを閉じます。ここで、応答についてサービスからユーザーに通知を送信したいと考えています。
助言がありますか?。
通知:
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(
getApplicationContext());
Intent intent = new Intent(getApplicationContext(),
YourActivity.class);
intent.setAction("notification");
PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, i intent,PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
builder.setSmallIcon(R.drawable.app_icon)
.setContentTitle("Next Appoinment....")
.setContentText(response)
.setTicker("Ticker")
.setLights(0xFFFF0000, 500, 500)
// setLights (int argb, int onMs, int offMs)
.setContentIntent(pendingIntent)
.setAutoCancel(true);
Notification notification = builder.getNotification();
notificationManager.notify(R.drawable.app_icon,
notification);