LocalNotification avec AlarmManager et BroadcastReceiver pas de tir Android, O (oreo)

Bonjour j'ai mes notifications locales en cours d'exécution sur les androïdes avant SDK 26

Mais dans un Android O j'ai le message d'avertissement suivant, et le récepteur de radiodiffusion n'est pas déclenché.

W/BroadcastQueue: Background execution not allowed: receiving Intent { act=package.name.action.LOCAL_NOTIFICATION cat=[com.category.LocalNotification] flg=0x14 (has extras) } to package.name/com.category.localnotifications.LocalNotificationReceiver

De ce que j'ai lu récepteurs de radiodiffusion sont plus limités dans android O, mais si oui, comment dois-je planifier la diffusion, si je le veux lancer, même si la principale activité n'est pas en cours d'exécution?

Dois-je utiliser les services au lieu de récepteurs?

C'est le AlarmManager lancer code:

public void Schedule(String aID, String aTitle, String aBody, int aNotificationCode, long aEpochTime)
{
    Bundle lExtras = new Bundle();
    lExtras.putInt("icon", f.getDefaultIcon());
    lExtras.putString("title", aTitle);
    lExtras.putString("message", aBody);
    lExtras.putString("id", aID);
    lExtras.putInt("requestcode", aNotificationCode);

    Intent lIntent = 
      new Intent(LocalNotificationScheduler.ACTION_NAME)
      .addCategory(NotificationsUtils.LocalNotifCategory)
      .putExtras(lExtras);

    PendingIntent lPendIntent = PendingIntent.getBroadcast(f.getApplicationContext(), aNotificationCode,
                                                           lIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager lAlarmMgr = (AlarmManager) f.getSystemService(Context.ALARM_SERVICE);
    lAlarmMgr.set(AlarmManager.RTC, 1000, lPendIntent);
}

C'est le récepteur de code:

public class LocalNotificationReceiver extends BroadcastReceiver {

public static native void   nativeReceiveLocalNotification (String aID, String aTitle, String aMessage, boolean aOnForeground );

/** This method receives the alarms set by LocalNotificationScheduler,
*   notifies the CAndroidNotifications c++ class, and (if needed) ships a notification banner 
*/
@Override
public void onReceive(Context aContext, Intent aIntent)
{
    Toast.makeText(context, text, duration).show();
}

}

C'est le manifeste:

<receiver android:name="com.category.localnotifications.LocalNotificationReceiver">
        <intent-filter>
            <action android:name="${applicationId}.action.LOCAL_NOTIFICATION" />
            <category android:name="com.category.LocalNotification" />
        </intent-filter>
    </receiver>
vérifier oreo lignes directrices, les services en arrière-plan a été supprimé. Utilisation planificateur de travail ou de la tâche lorsque l'application est en arrière plan.
Oui mais je veux recevoir une notification après un certain temps, même si l'activité principale n'est pas en cours d'exécution juste comme il était en marche avant. Est-ce possible?
Pouvez-vous essayer de démarrer l'intention explicitement comme dans gist.github.com/yccheok/d39b434470a4135104efae76ec75afc2 ?

OriginalL'auteur Hug | 2017-08-22