уведомление не отображается - PullRequest
0 голосов
/ 15 декабря 2018

Я пытаюсь настроить уведомление для своего приложения, где пользователь может добавить в избранное ТВ-шоу, и, исходя из эфирного времени, он получит уведомление.Я делал тестовый запуск с настройкой через 5 минут после текущего времени, уведомление не отображается.Может кто-нибудь помочь?спасибо

Это код, в котором я установил настройки и показывает уведомление.Это в настоящее время в моем классе базы данных, потому что я тяну время, основанное на любимом пользователем времени ТВ-шоу.

    public static void setNotification(int mTime) {
    Calendar calendar = Calendar.getInstance();
    Calendar setCalendar = Calendar.getInstance();
    setCalendar.set(Calendar.HOUR_OF_DAY, mTime);


    if(setCalendar.before(calendar))
        setCalendar.add(Calendar.DATE,1);

        ComponentName receiver = new ComponentName(mContext, AlarmReceiver.class);
        PackageManager packageManager = mContext.getPackageManager();
        packageManager.setComponentEnabledSetting(receiver,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);

        Intent intent1 = new Intent(mContext, AlarmReceiver.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext,
                DAILY_REMINDER_REQUEST_CODE, intent1,
                PendingIntent.FLAG_UPDATE_CURRENT);
        AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(ALARM_SERVICE);
        alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, setCalendar.getTimeInMillis(),
                AlarmManager.INTERVAL_DAY, pendingIntent);
}


public static void showNotification(String title, String mShowName, String content)
{
        Intent notificationIntent = new Intent(mContext, AlarmReceiver.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
        stackBuilder.addParentStack(SplashActivity.class);
        stackBuilder.addNextIntent(notificationIntent);

        PendingIntent pendingIntent = stackBuilder.getPendingIntent(DAILY_REMINDER_REQUEST_CODE, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);

        Notification notification = builder.setContentTitle(title)
                .setContentText(mShowName + content)
                .setAutoCancel(true)
                .setSmallIcon(R.mipmap.ic_launcher_round)
                .setContentIntent(pendingIntent).build();

        NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(DAILY_REMINDER_REQUEST_CODE, notification);
}

Это класс вещателя тревоги

    public class AlarmReceiver extends BroadcastReceiver {

String TAG = "AlarmReceiver";
int mTime;

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub

    if (intent.getAction() != null && context != null) {
        if (intent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
            // Set the alarm here.
            Log.d(TAG, "onReceive: BOOT_COMPLETED");
            Database db = new Database(context);
            Database.setNotification(mTime);
            Log.d(TAG, "alarmPass");
            return;
        }
    }

    Log.d(TAG, "onReceive: ");

    //Trigger the notification
    Database.showNotification("MediaHub Alert", "",
            "is live right now.");
}

Это кодв манифесте Android.

    <receiver android:name=".Database.AlarmReceiver"
        android:enabled="false">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>

Спасибо за внимание.Я был бы очень признателен, если бы кто-то посмотрел на это.

...