android нотификация само звук възпроизвежда известието не се показва в чекмеджето за известия

Опитвам се да пусна известие в определен момент с помощта на AlarmManager и Notification manager. изправен съм пред странен проблем. когато се задейства известие, възпроизвежда се само звук, но известието не се показва в чекмеджето за известия. получих грешка в дневника

04-26 11:32:09.217    1222-1222/? E/NotificationService﹕ WARNING: In a future release this will crash the app: com.example.shiv.selftweak

моят код е.

Класът, който извиква AlarmManager

        Intent intent1 = new Intent(this, FireNotification.class);
        PendingIntent pendingIntent = PendingIntent.getService(this, 1000, intent1, 0);
        AlarmManager am = (AlarmManager)this.getSystemService(ALARM_SERVICE);
        am.set(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),  pendingIntent);

Клас FireNotification

public class FireNotification extends Service {

    @Override
    public void onCreate() {
        Intent intent = new Intent(this, MainActivity.class);
        long[] pattern = {0, 300, 0};
        PendingIntent pi = PendingIntent.getActivity(this, 1234, intent, 0);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setContentTitle("Self tweak")
                .setContentText("Habbits are waiting for last dones")
                .setVibrate(pattern)
                .setAutoCancel(false);

        mBuilder.setContentIntent(pi);
        mBuilder.setDefaults(Notification.DEFAULT_SOUND);
        mBuilder.setAutoCancel(false);
        NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
        mNotificationManager.notify(1234, mBuilder.build());
    }

@Override
public IBinder onBind(Intent intent) {
    return null;
}

}

Android Menifest

 <service android:name=".FireNotification"></service>
        <intent-filter>

            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>

когато известието се задейства, възпроизвежда се само звук. но не се показва в чекмеджето за известия, което не показва известие.


person shiv garg    schedule 26.04.2015    source източник


Отговори (1)


Проблемът е, че не сте посочили mBuilder.setSmallIcon(R.drawable.ic_launcher).

По принцип трябва да зададете smallIcon, contentTitle и contentText. Ако пропуснете някое от тях, известието изобщо няма да се покаже! Това е ясно посочено ТУК (също можете да прочетете повече за известия там също).

person Vesko    schedule 26.04.2015
comment
да и аз разбрах същото. Благодаря. но android трябва да хвърли изключение за същото - person shiv garg; 27.04.2015