0
난 그냥 응용 프로그램은 내가 notifications.When 앱은 내가 통지를안드로이드 백그라운드 서비스가 실행하지만, 통지
protected void onHandleIntent(Intent intent) {
final ResultReceiver receiver = intent.getParcelableExtra("receiver");
String url = intent.getStringExtra("url");
Bundle bundle = new Bundle();
for(;;) {
if (!TextUtils.isEmpty(url)) {
receiver.send(STATUS_RUNNING, Bundle.EMPTY);
try {
String results = downloadData(url);
if (null != results) {
bundle.putString("result", results);
receiver.send(STATUS_FINISHED, bundle);
displayNotification(results);
}
} catch (Exception e) {
bundle.putString(Intent.EXTRA_TEXT, e.toString());
receiver.send(STATUS_ERROR, bundle);
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
이 무엇입니까 개방되어지고 있지 않다 닫혀 app.When 작은 채팅을 구현하고를 받고 있지 않습니다 액티비티 코드입니다. 버튼의 클릭에 내가 서비스를 시작하고 있고 응용 프로그램이 opened.When 응용 프로그램입니다 때 작동하는 폐쇄 된 서비스가이
protected void displayNotification(String msg) {
Log.i("Start", "notification");
NotificationManager mNotificationManager;
int numMessages = 0;
/* Invoking the default notification service */
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
mBuilder.setContentTitle("New Message");
mBuilder.setContentText("You've received new message.");
mBuilder.setTicker("New Message Alert!");
mBuilder.setSmallIcon(R.drawable.ic_launcher);
/* Increase notification number every time a new notification arrives */
mBuilder.setNumber(++numMessages);
/* Add Big View Specific Configuration */
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
String[] events = new String[6];
events[0] = msg;
// Sets a title for the Inbox style big view
inboxStyle.setBigContentTitle("Big Title Details:");
// Moves events into the big view
for (int i=0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
mBuilder.setStyle(inboxStyle);
/* Creates an explicit intent for an Activity in your app */
Intent resultIntent = new Intent(this, NotificationView.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(NotificationView.class);
/* Adds the Intent that starts the Activity to the top of the stack */
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
/* notificationID allows you to update the notification later on. */
mNotificationManager.notify(1, mBuilder.build());
}
mmm ... 푸시 알림을 사용하지 않으시겠습니까? – Aspicas
stopSelf() 또는 stopService (..)를 호출하지 않으시겠습니까 –
서비스 코드 – Anjali