을 보여 가져올 수 없습니다 ... 나는 this 가이드를 따라하고, 그것이 doInBackground()
방법에서라고 AsyncTask
에 다음 코드를 생성 :알림이 상태 표시 줄 알림이 동작하지 않습니다
private void newNotification(int count) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(handler.getContext());
builder.setContentTitle("New Notification");
builder.setContentText("Testing notification");
builder.setNumber(count);
// Creates an explicit intent for an Activity in your app
Intent intent = new Intent(handler.getContext(), MainActivity.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(handler.getContext());
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(MainActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) handler.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, builder.build());
}
handler
내가 매개 변수를 1로 전화를 몇 가지 이유를 들어 MainActivity
의 this.getContext()
을 반환 getContext()
를 구현하는 인터페이스를 사용하여, MainActivity
에 대한 참조입니다 아무 일도 발생하지 않습니다.
@Override
protected String[] doInBackground(String... empty) {
newNotification(1);
return null;
}
디버그는 코드의 모든 행은 실행 중이지만 알림은 표시되지 않음을 보여줍니다. 특수 권한에 대한 언급이 없거나 UI 스레드에서 실행해야합니다. 백그라운드 서비스는 메시지가 도착할 때처럼 알려주 려하기 때문입니다.
내가 뭘 잘못했는지 아이디어가 있습니까?
보면,이 사람은이 질문에 자신 http://stackoverflow.com/questions/16314964/notification-sony-devices-으로, 자신의 특정 장치에 메신저 빌더를 사용하여 있다고 말했다 do not-show-any-notification/16315199 # 16315199 – JRowan
hmmm .. 음 Xperia가 아닌 Nexus 4를 사용하고 있습니다. 재고가 충분해야 안드로이드가 잘 작동 할 것으로 기대합니다 ... 작성자는 공식 google의 일부입니다. 결국 SDK. 다른 사람이 뭔가를 알고 있는지 보자. 필자는 자신의 알림을 만드는 것보다 빌더를 사용하는 것을 선호합니다. – tbkn23
AsyncTask의 onPostExecute() 또는 onProgressUpdate()를 시도하십시오. 알림은 UIthread로 처리해야합니다. – JRowan