You need to send a post request to the server in order to check if there are notifications for this application. How to implement it, I have no idea. I used one service PushBots, it does not send notifications to phones like Meizu. The point is, the user has closed the application, does his own business, and the background tasks of the application in the background send a request every 30 seconds and if there are notifications, notify the user

Intent intent= new Intent(this, NotificationListener.getClass()); startService(intent); 

So in MainActivity I declare my service

 public class NotificationListener extends Service { private SharedPreferences sharedPreferences; private SharedPreferences.Editor editor; public NotificationListener() { } public static final int JOB_ID = 0x01; @Override public IBinder onBind(Intent intent) { throw new UnsupportedOperationException("Not yet implemented"); } @Override public int onStartCommand(Intent intent, int flags, int startId) { sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); editor = sharedPreferences.edit(); final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Post post = (Post) new Post().execute("тут url", "user_id=" + sharedPreferences.getInt("userId",0)); try { ShowNotification(post.get()); } catch (ExecutionException e) { Log.i("MSG","SOMETHING ERROR " + e); } catch (InterruptedException e) { Log.i("MSG","SOMETHING ERROR " + e); } handler.postDelayed(this, 10000); } }, 0); return START_STICKY; } private void ShowNotification(String result) { JSONObject dataJsonObj = null; try { dataJsonObj = new JSONObject(result); if (dataJsonObj.has("notification")) { JSONArray getNotify = dataJsonObj.getJSONArray("notification"); String content = ""; for (int i = 0; i < getNotify.length(); i++) { JSONObject notify = getNotify.getJSONObject(i); content += notify.getString("content"); } Intent notifyIntent = new Intent(this, MainActivity.class); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(this); //builder.setContentIntent(pendingIntent); builder.setContentTitle("У вас новый заказ!"); NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.setBigContentTitle("У вас новый заказ!"); bigTextStyle.bigText(content); builder.setContentText(content); builder.setStyle(bigTextStyle); builder.setAutoCancel(true); builder.setDefaults(Notification.DEFAULT_SOUND); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setContentIntent(pendingIntent); Bitmap largeIconBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.logo); builder.setLargeIcon(largeIconBitmap); builder.setFullScreenIntent(pendingIntent, true); Notification notification = builder.build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(1, notification); startForeground(1, notification); } } catch (JSONException e) { e.printStackTrace(); } } } 

Android Manifest

  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.QUICKBOOT_POWERON" /> <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> <service android:name=".NotificationListener"></service> 
  • Select a separate stream for this task and in the background make your POST sending. Through any library with which it will be convenient for you to work. It also depends on the format in which JSON / * XML or something else is received by the server. Meizu has nothing to do with it, we can test the application locally from a computer, through all sorts of emulators - Dred
  • JSON format. I'm worried about exactly the question of how to start something to work in the background, with the application turned off. 7 hours spent in Google does not work - MaxKuz
  • Well, it’s right, if the code was written for 7 o'clock and it wouldn’t work, then it’s understandable, and so ... just reading and not writing anything, of course will not work))) So you’ll have to start. And here it is . For a long time I did not write on android, but in appearance it is not difficult to understand. What exactly is the problem? The code in the studio - Dred
  • You understand what the problem is, the services in the form that they offer in Google work on a real Meizu device, but do not work on Le Eco. During these 7 hours, my brain no longer cooks - MaxKuz
  • So therefore I say, show the code, say where the error is or where the lock occurs. Otherwise, you take wireshark to see where packets are lost, if you don’t even see what can come back in the debugger. - Dred

0