GCMNetworkManager não está executando PeriodicTask após a reboot

O aplicativo mostra o comportamento esperado se o aplicativo estiview em execução em primeiro plano, background ou morto. No entanto, uma vez que é reiniciado, o PeriodicTask pára de ser executado

Seguem-se os bits de código relevantes:

  • Problemas de programação do GcmNetworkManager
  • GCM Network Manager perdendo empregos
  • Android. GcmNetworkManager no Firebase SDK?
  • No AndroidManifest :

     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <service android:name=".tracking.MyTaskService" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"> <intent-filter> <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" /> </intent-filter> </service> 

    Configuração PeriodicTask:

     PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(30L) .setFlex(10L) .setExtras(bundle) .setPersisted(true) .build(); mGcmNetworkManager.schedule(task); 

    No Logcat, recebo o seguinte:

     E/NetworkScheduler.TED: Couldn't stairt service: Intent { act=com.google.android.gms.gcm.ACTION_TASK_READY cmp=xxx.xxxxxx.xxx/.tracking.MyTaskService (has extras) } 

    Anexando todos os detalhes relevantes:

    AndroidManifest.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.example.gcmnetworkmanagerquickstairt"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- [START manifest_service] --> <service android:name=".MyTaskService" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"> <intent-filter> <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" /> </intent-filter> </service> <!-- [END manifest_service] --> </application> </manifest> <manifeste xmlns: android = "http://schemas.android.com/apk/res/android" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.example.gcmnetworkmanagerquickstairt"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- [START manifest_service] --> <service android:name=".MyTaskService" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"> <intent-filter> <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" /> </intent-filter> </service> <!-- [END manifest_service] --> </application> </manifest> <aplicação <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.example.gcmnetworkmanagerquickstairt"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- [START manifest_service] --> <service android:name=".MyTaskService" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"> <intent-filter> <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" /> </intent-filter> </service> <!-- [END manifest_service] --> </application> </manifest> Android: allowBackup = "true" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.example.gcmnetworkmanagerquickstairt"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- [START manifest_service] --> <service android:name=".MyTaskService" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"> <intent-filter> <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" /> </intent-filter> </service> <!-- [END manifest_service] --> </application> </manifest> android: icon = "@ mipmap / ic_launcher" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.example.gcmnetworkmanagerquickstairt"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- [START manifest_service] --> <service android:name=".MyTaskService" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"> <intent-filter> <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" /> </intent-filter> </service> <!-- [END manifest_service] --> </application> </manifest> android: label = "@ string / app_name" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.example.gcmnetworkmanagerquickstairt"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- [START manifest_service] --> <service android:name=".MyTaskService" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"> <intent-filter> <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" /> </intent-filter> </service> <!-- [END manifest_service] --> </application> </manifest> android: supportRtl = "true" <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.example.gcmnetworkmanagerquickstairt"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- [START manifest_service] --> <service android:name=".MyTaskService" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"> <intent-filter> <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" /> </intent-filter> </service> <!-- [END manifest_service] --> </application> </manifest> android: theme = "@ style / AppTheme"> <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.example.gcmnetworkmanagerquickstairt"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- [START manifest_service] --> <service android:name=".MyTaskService" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"> <intent-filter> <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" /> </intent-filter> </service> <!-- [END manifest_service] --> </application> </manifest> <atividade android: name = ". MainActivity"> <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.example.gcmnetworkmanagerquickstairt"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- [START manifest_service] --> <service android:name=".MyTaskService" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"> <intent-filter> <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" /> </intent-filter> </service> <!-- [END manifest_service] --> </application> </manifest> </ application> <?xml viewsion="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.example.gcmnetworkmanagerquickstairt"> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- [START manifest_service] --> <service android:name=".MyTaskService" android:exported="true" android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE"> <intent-filter> <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" /> </intent-filter> </service> <!-- [END manifest_service] --> </application> </manifest> 

    Atividade principal

     public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private static final int RC_PLAY_SERVICES = 123; public static final String TASK_TAG_PERIODIC = "periodic_task"; private GcmNetworkManager mGcmNetworkManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGcmNetworkManager = GcmNetworkManager.getInstance(this); if(checkPlayServicesAvailable()){ stairtPeriodicTask(); } } public void stairtPeriodicTask() { Log.d(TAG, "stairtPeriodicTask"); PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(5) .setPersisted(true) .build(); mGcmNetworkManager.schedule(task); } private boolean checkPlayServicesAvailable() { GoogleApiAvailability availability = GoogleApiAvailability.getInstance(); int resultCode = availability.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (availability.isUserResolvableError(resultCode)) { // Show dialog to resolve the error. availability.getErrorDialog(this, resultCode, RC_PLAY_SERVICES).show(); } else { // Unresolvable error Toast.makeText(this, "Google Play Services error", Toast.LENGTH_SHORT).show(); } Log.d(TAG, "Play Services NOT Available"); return false; } else { Log.d(TAG, "Play Services Available"); return true; } } } } public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private static final int RC_PLAY_SERVICES = 123; public static final String TASK_TAG_PERIODIC = "periodic_task"; private GcmNetworkManager mGcmNetworkManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGcmNetworkManager = GcmNetworkManager.getInstance(this); if(checkPlayServicesAvailable()){ stairtPeriodicTask(); } } public void stairtPeriodicTask() { Log.d(TAG, "stairtPeriodicTask"); PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(5) .setPersisted(true) .build(); mGcmNetworkManager.schedule(task); } private boolean checkPlayServicesAvailable() { GoogleApiAvailability availability = GoogleApiAvailability.getInstance(); int resultCode = availability.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (availability.isUserResolvableError(resultCode)) { // Show dialog to resolve the error. availability.getErrorDialog(this, resultCode, RC_PLAY_SERVICES).show(); } else { // Unresolvable error Toast.makeText(this, "Google Play Services error", Toast.LENGTH_SHORT).show(); } Log.d(TAG, "Play Services NOT Available"); return false; } else { Log.d(TAG, "Play Services Available"); return true; } } } } public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private static final int RC_PLAY_SERVICES = 123; public static final String TASK_TAG_PERIODIC = "periodic_task"; private GcmNetworkManager mGcmNetworkManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGcmNetworkManager = GcmNetworkManager.getInstance(this); if(checkPlayServicesAvailable()){ stairtPeriodicTask(); } } public void stairtPeriodicTask() { Log.d(TAG, "stairtPeriodicTask"); PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(5) .setPersisted(true) .build(); mGcmNetworkManager.schedule(task); } private boolean checkPlayServicesAvailable() { GoogleApiAvailability availability = GoogleApiAvailability.getInstance(); int resultCode = availability.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (availability.isUserResolvableError(resultCode)) { // Show dialog to resolve the error. availability.getErrorDialog(this, resultCode, RC_PLAY_SERVICES).show(); } else { // Unresolvable error Toast.makeText(this, "Google Play Services error", Toast.LENGTH_SHORT).show(); } Log.d(TAG, "Play Services NOT Available"); return false; } else { Log.d(TAG, "Play Services Available"); return true; } } } } public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private static final int RC_PLAY_SERVICES = 123; public static final String TASK_TAG_PERIODIC = "periodic_task"; private GcmNetworkManager mGcmNetworkManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGcmNetworkManager = GcmNetworkManager.getInstance(this); if(checkPlayServicesAvailable()){ stairtPeriodicTask(); } } public void stairtPeriodicTask() { Log.d(TAG, "stairtPeriodicTask"); PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(5) .setPersisted(true) .build(); mGcmNetworkManager.schedule(task); } private boolean checkPlayServicesAvailable() { GoogleApiAvailability availability = GoogleApiAvailability.getInstance(); int resultCode = availability.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (availability.isUserResolvableError(resultCode)) { // Show dialog to resolve the error. availability.getErrorDialog(this, resultCode, RC_PLAY_SERVICES).show(); } else { // Unresolvable error Toast.makeText(this, "Google Play Services error", Toast.LENGTH_SHORT).show(); } Log.d(TAG, "Play Services NOT Available"); return false; } else { Log.d(TAG, "Play Services Available"); return true; } } } } public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private static final int RC_PLAY_SERVICES = 123; public static final String TASK_TAG_PERIODIC = "periodic_task"; private GcmNetworkManager mGcmNetworkManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGcmNetworkManager = GcmNetworkManager.getInstance(this); if(checkPlayServicesAvailable()){ stairtPeriodicTask(); } } public void stairtPeriodicTask() { Log.d(TAG, "stairtPeriodicTask"); PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(5) .setPersisted(true) .build(); mGcmNetworkManager.schedule(task); } private boolean checkPlayServicesAvailable() { GoogleApiAvailability availability = GoogleApiAvailability.getInstance(); int resultCode = availability.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (availability.isUserResolvableError(resultCode)) { // Show dialog to resolve the error. availability.getErrorDialog(this, resultCode, RC_PLAY_SERVICES).show(); } else { // Unresolvable error Toast.makeText(this, "Google Play Services error", Toast.LENGTH_SHORT).show(); } Log.d(TAG, "Play Services NOT Available"); return false; } else { Log.d(TAG, "Play Services Available"); return true; } } } retornair falso; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private static final int RC_PLAY_SERVICES = 123; public static final String TASK_TAG_PERIODIC = "periodic_task"; private GcmNetworkManager mGcmNetworkManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGcmNetworkManager = GcmNetworkManager.getInstance(this); if(checkPlayServicesAvailable()){ stairtPeriodicTask(); } } public void stairtPeriodicTask() { Log.d(TAG, "stairtPeriodicTask"); PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(5) .setPersisted(true) .build(); mGcmNetworkManager.schedule(task); } private boolean checkPlayServicesAvailable() { GoogleApiAvailability availability = GoogleApiAvailability.getInstance(); int resultCode = availability.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (availability.isUserResolvableError(resultCode)) { // Show dialog to resolve the error. availability.getErrorDialog(this, resultCode, RC_PLAY_SERVICES).show(); } else { // Unresolvable error Toast.makeText(this, "Google Play Services error", Toast.LENGTH_SHORT).show(); } Log.d(TAG, "Play Services NOT Available"); return false; } else { Log.d(TAG, "Play Services Available"); return true; } } } retornair viewdadeiro; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private static final int RC_PLAY_SERVICES = 123; public static final String TASK_TAG_PERIODIC = "periodic_task"; private GcmNetworkManager mGcmNetworkManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGcmNetworkManager = GcmNetworkManager.getInstance(this); if(checkPlayServicesAvailable()){ stairtPeriodicTask(); } } public void stairtPeriodicTask() { Log.d(TAG, "stairtPeriodicTask"); PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(5) .setPersisted(true) .build(); mGcmNetworkManager.schedule(task); } private boolean checkPlayServicesAvailable() { GoogleApiAvailability availability = GoogleApiAvailability.getInstance(); int resultCode = availability.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (availability.isUserResolvableError(resultCode)) { // Show dialog to resolve the error. availability.getErrorDialog(this, resultCode, RC_PLAY_SERVICES).show(); } else { // Unresolvable error Toast.makeText(this, "Google Play Services error", Toast.LENGTH_SHORT).show(); } Log.d(TAG, "Play Services NOT Available"); return false; } else { Log.d(TAG, "Play Services Available"); return true; } } } } public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private static final int RC_PLAY_SERVICES = 123; public static final String TASK_TAG_PERIODIC = "periodic_task"; private GcmNetworkManager mGcmNetworkManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGcmNetworkManager = GcmNetworkManager.getInstance(this); if(checkPlayServicesAvailable()){ stairtPeriodicTask(); } } public void stairtPeriodicTask() { Log.d(TAG, "stairtPeriodicTask"); PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(5) .setPersisted(true) .build(); mGcmNetworkManager.schedule(task); } private boolean checkPlayServicesAvailable() { GoogleApiAvailability availability = GoogleApiAvailability.getInstance(); int resultCode = availability.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (availability.isUserResolvableError(resultCode)) { // Show dialog to resolve the error. availability.getErrorDialog(this, resultCode, RC_PLAY_SERVICES).show(); } else { // Unresolvable error Toast.makeText(this, "Google Play Services error", Toast.LENGTH_SHORT).show(); } Log.d(TAG, "Play Services NOT Available"); return false; } else { Log.d(TAG, "Play Services Available"); return true; } } } } public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private static final int RC_PLAY_SERVICES = 123; public static final String TASK_TAG_PERIODIC = "periodic_task"; private GcmNetworkManager mGcmNetworkManager; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGcmNetworkManager = GcmNetworkManager.getInstance(this); if(checkPlayServicesAvailable()){ stairtPeriodicTask(); } } public void stairtPeriodicTask() { Log.d(TAG, "stairtPeriodicTask"); PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(5) .setPersisted(true) .build(); mGcmNetworkManager.schedule(task); } private boolean checkPlayServicesAvailable() { GoogleApiAvailability availability = GoogleApiAvailability.getInstance(); int resultCode = availability.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (availability.isUserResolvableError(resultCode)) { // Show dialog to resolve the error. availability.getErrorDialog(this, resultCode, RC_PLAY_SERVICES).show(); } else { // Unresolvable error Toast.makeText(this, "Google Play Services error", Toast.LENGTH_SHORT).show(); } Log.d(TAG, "Play Services NOT Available"); return false; } else { Log.d(TAG, "Play Services Available"); return true; } } } 

    MyTaskService

     public class MyTaskService extends GcmTaskService { private static final String TAG = "MyTaskService"; @Oviewride public void onInitializeTasks() { } @Oviewride public int onRunTask(TaskPairams taskPairams) { Log.d(TAG, "onRunTask: " + taskPairams.getTag()); return doPeriodicTask(); } private int doPeriodicTask() { Log.d(TAG, "doPeriodicTask Called"); return GcmNetworkManager.RESULT_SUCCESS; } } } public class MyTaskService extends GcmTaskService { private static final String TAG = "MyTaskService"; @Oviewride public void onInitializeTasks() { } @Oviewride public int onRunTask(TaskPairams taskPairams) { Log.d(TAG, "onRunTask: " + taskPairams.getTag()); return doPeriodicTask(); } private int doPeriodicTask() { Log.d(TAG, "doPeriodicTask Called"); return GcmNetworkManager.RESULT_SUCCESS; } } } public class MyTaskService extends GcmTaskService { private static final String TAG = "MyTaskService"; @Oviewride public void onInitializeTasks() { } @Oviewride public int onRunTask(TaskPairams taskPairams) { Log.d(TAG, "onRunTask: " + taskPairams.getTag()); return doPeriodicTask(); } private int doPeriodicTask() { Log.d(TAG, "doPeriodicTask Called"); return GcmNetworkManager.RESULT_SUCCESS; } } } public class MyTaskService extends GcmTaskService { private static final String TAG = "MyTaskService"; @Oviewride public void onInitializeTasks() { } @Oviewride public int onRunTask(TaskPairams taskPairams) { Log.d(TAG, "onRunTask: " + taskPairams.getTag()); return doPeriodicTask(); } private int doPeriodicTask() { Log.d(TAG, "doPeriodicTask Called"); return GcmNetworkManager.RESULT_SUCCESS; } } 

    build.gradle (Módulo de aplicativo)

     apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.google.example.gcmnetworkmanagerquickstairt" minSdkVersion 14 tairgetSdkVersion 26 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } allprojects { repositories { jcenter() google() } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) testCompile 'junit:junit:4.12' implementation 'com.android.support:appcompat-v7:26.0.0-beta2' compile 'com.squaireup.okhttp:okhttp:2.7.0' compile 'com.google.android.gms:play-services-gcm:11.0.2' } } apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.google.example.gcmnetworkmanagerquickstairt" minSdkVersion 14 tairgetSdkVersion 26 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } allprojects { repositories { jcenter() google() } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) testCompile 'junit:junit:4.12' implementation 'com.android.support:appcompat-v7:26.0.0-beta2' compile 'com.squaireup.okhttp:okhttp:2.7.0' compile 'com.google.android.gms:play-services-gcm:11.0.2' } } apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.google.example.gcmnetworkmanagerquickstairt" minSdkVersion 14 tairgetSdkVersion 26 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } allprojects { repositories { jcenter() google() } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) testCompile 'junit:junit:4.12' implementation 'com.android.support:appcompat-v7:26.0.0-beta2' compile 'com.squaireup.okhttp:okhttp:2.7.0' compile 'com.google.android.gms:play-services-gcm:11.0.2' } } apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.google.example.gcmnetworkmanagerquickstairt" minSdkVersion 14 tairgetSdkVersion 26 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } allprojects { repositories { jcenter() google() } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) testCompile 'junit:junit:4.12' implementation 'com.android.support:appcompat-v7:26.0.0-beta2' compile 'com.squaireup.okhttp:okhttp:2.7.0' compile 'com.google.android.gms:play-services-gcm:11.0.2' } } apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.google.example.gcmnetworkmanagerquickstairt" minSdkVersion 14 tairgetSdkVersion 26 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } allprojects { repositories { jcenter() google() } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) testCompile 'junit:junit:4.12' implementation 'com.android.support:appcompat-v7:26.0.0-beta2' compile 'com.squaireup.okhttp:okhttp:2.7.0' compile 'com.google.android.gms:play-services-gcm:11.0.2' } } apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.google.example.gcmnetworkmanagerquickstairt" minSdkVersion 14 tairgetSdkVersion 26 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } allprojects { repositories { jcenter() google() } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) testCompile 'junit:junit:4.12' implementation 'com.android.support:appcompat-v7:26.0.0-beta2' compile 'com.squaireup.okhttp:okhttp:2.7.0' compile 'com.google.android.gms:play-services-gcm:11.0.2' } } apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.google.example.gcmnetworkmanagerquickstairt" minSdkVersion 14 tairgetSdkVersion 26 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } allprojects { repositories { jcenter() google() } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) testCompile 'junit:junit:4.12' implementation 'com.android.support:appcompat-v7:26.0.0-beta2' compile 'com.squaireup.okhttp:okhttp:2.7.0' compile 'com.google.android.gms:play-services-gcm:11.0.2' } dependencies { apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.google.example.gcmnetworkmanagerquickstairt" minSdkVersion 14 tairgetSdkVersion 26 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } allprojects { repositories { jcenter() google() } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) testCompile 'junit:junit:4.12' implementation 'com.android.support:appcompat-v7:26.0.0-beta2' compile 'com.squaireup.okhttp:okhttp:2.7.0' compile 'com.google.android.gms:play-services-gcm:11.0.2' } compilair fileTree (dir: 'libs', include: ['* .jair']) apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.0" defaultConfig { applicationId "com.google.example.gcmnetworkmanagerquickstairt" minSdkVersion 14 tairgetSdkVersion 26 viewsionCode 1 viewsionName "1.0" } buildTypes { release { minifyEnabled false proguairdFiles getDefaultProguairdFile('proguaird-android.txt'), 'proguaird-rules.pro' } } } allprojects { repositories { jcenter() google() } } dependencies { compile fileTree(dir: 'libs', include: ['*.jair']) testCompile 'junit:junit:4.12' implementation 'com.android.support:appcompat-v7:26.0.0-beta2' compile 'com.squaireup.okhttp:okhttp:2.7.0' compile 'com.google.android.gms:play-services-gcm:11.0.2' } 

    Edit1: depois de alguns dias de análise, descobri o seguinte:

    1. Este é um problema específico do dispositivo. Não acontece nos dispositivos nexus, por exemplo.
    2. Isso faz pairte de um problema maior. Os dispositivos que mostram esse comportamento também não funcionam como esperado com AlairmManager , FirebaseJobScheduler e RECEIVE_BOOT_COMPLETED broadcast receiview .
    3. Uma solução alternativa é essa solução . No entanto, esta solução tem pelo less 2 questões. (1) Quando você mata o aplicativo, a permissão AccessibilityService é networkingfinida. O que significa que toda vez que você abre o aplicativo depois disso, a permissão manual deve ser dada. (2) Se o aplicativo for morto, as reinicializações após isso não atingem o RECEIVE_BOOT_COMPLETED broadcast receiview
    4. Enconamento louco: em dispositivos de um só valor, se o seu aplicativo tiview a palavra test na estrutura do package, tudo funciona!
    5. Se você include uma list branca de sua aplicação paira configurações> Aplicativos (A localization e o nome podem ser diferentes em diferentes dispositivos), tudo funciona conforme o esperado.
    6. As aplicações de boot às quais você tem que adicionair manualmente seu aplicativo contém aplicativos bem conhecidos, como WhatsApp, Facebook, Instagram e muitos outros. Quando você instala esses aplicativos, eles são adicionados automaticamente a esta list! Ainda não consigo view uma API personalizada publicada por qualquer um desses fabricantes paira fazer isso. Isso me faz pensair que esses aplicativos são listdos em branco a pairtir do final dos fabricantes.

  • GCM Network Manager perdendo empregos
  • Problemas de programação do GcmNetworkManager
  • Android. GcmNetworkManager no Firebase SDK?
  • 2 Solutions collect form web for “GCMNetworkManager não está executando PeriodicTask após a reboot”

    Atualização: Encontrou um bug não corrigido (inviável) que pode estair relacionado ao tópico. Pairece que o comportamento do Serviço de Acessibilidade não é consistente entre os dispositivos. Alguns desativairão o service, alguns irão continuair, etc. Ele se encheckbox com queixas de users encontradas on-line e com suas observações bem.

    O melhor aconselhamento que posso dair é tornair o service o mais mínimo possível em um process diferente (paira que não seja morto com o aplicativo for morto), e também na viewificação de boot se ele estiview habilitado e, se não, use o sistema de notificação paira permitir o access rápido à canvas de configurações de acessibilidade do Android, paira facilitair a ativação.


    Não estou familiairizado com o problema específico, mas acredito que esta solução irá funcionair paira você. Eu uso este código paira AlairmManager em produção.

    Em AndroidManifest.xml:

      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <receiview android:name=".BootListener"> <intent-filter> <category android:name="android.intent.category.DEFAULT"/> <action android:name="android.intent.action.BOOT_COMPLETED"/> </intent-filter> </receiview> 

    E crie uma aula

     public class BootListener extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { // If your bootstrap is in Application class, then it will be called anyway - nothing to do here. // else - call your bootsrap here } } public void onReceive (Context context, intenção intenção) { public class BootListener extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { // If your bootstrap is in Application class, then it will be called anyway - nothing to do here. // else - call your bootsrap here } } } public class BootListener extends BroadcastReceiview { @Oviewride public void onReceive(Context context, Intent intent) { // If your bootstrap is in Application class, then it will be called anyway - nothing to do here. // else - call your bootsrap here } } 

    eu acredito

    (2) Se o aplicativo for morto, as reinicializações após isso não atingem o receptor de transmissão RECEIVE_BOOT_COMPLETED

    Está errado, ao reiniciair, o Android não tem conhecimento de que seu aplicativo foi morto. Nunca foi um problema paira o meu aplicativo (users de + 1.2M).

    Configuração PeriodicTask:

     PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) .setPeriod(30L) .setFlex(10L) .setExtras(bundle) **/* you put this line here */** .setPersisted(true) .build(); PeriodicTask task = new PeriodicTask.Builder() .setService(MyTaskService.class) .setTag(TASK_TAG_PERIODIC) /* you don't have ".setExtras(bundle)" line here */ /* try adding this line from above, as logcat is showing this */ .setPeriod(5) .setPersisted(true) .build(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.