큰 시스템의 프로토 타입 응용 프로그램을 구축 중입니다. 이 프로토 타입은 오프라인이지만 서버에서 정보를 얻는 것처럼 보입니다. 앱이 열려 있지 않은 경우에도 (DeamonThread 사용).백그라운드에서 AI의 Android 알림
그래서 Android 응용 프로그램을 만들었고 이제는 작업을 만들고 삭제하는 AI (응용 프로그램 내)를 추가하려고합니다. 그것은 작동하지만 DeamonThread에서 알림을 추가하려고하면 Thread가 Activity가 아니기 때문에 알림이 추가되지 않습니다.
변경하려고 시도했습니다. 확장 활동 실행 파일 실행 파일 하지만 Deamon으로 만들 수는 없습니다. 나는 쉽게 뭔가 빠진 것 같은
느낌 ..
public void run() {
while (counter < 100) {
try {
sleep(random.nextInt(10000));
} catch (InterruptedException e) {
e.printStackTrace();
}
Task task = new Task("AI", "this was the " + counter
+ " AI message", flow);
sendNotation();
}
counter++;
}
}
private void sendNotation() {
NotificationManager nm=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(this, Flippin.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
String body = "This is a message from Adam";
String title = "One new Task";
NotificationCompat.Builder n = new NotificationCompat.Builder(this);
n.setContentIntent(pi);
n.setSmallIcon(R.drawable.notif);
n.setContentTitle(title);
n.setContentText(body);
n.setDefaults(Notification.DEFAULT_ALL);
n.setAutoCancel(true);
nm.notify(uniqueID, n.build());
finish();
}