2017-02-17 66 views
4

即使在應用程序被終止後(不在後臺中),任何人都可以幫助我接收小米和聯想設備上的通知嗎?一旦應用程序在Android中的小米和聯想設備上遇害,則不會收到GCM通知

編輯1

我加入GCM廣播接收器。下面是代碼

內的AndroidManifest.xml

<receiver 
     android:name="com.don.offers.broadcast_receiver.GcmBroadcastReceiver" 
     android:permission="com.google.android.c2dm.permission.SEND" > 
     <intent-filter> 
      <!-- Receives the actual messages. --> 
      <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
      <category android:name="com.google.android.gcm.demo.app" /> 
     </intent-filter> 
    </receiver> 

GcmBroadcastReceiver.java

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     ComponentName comp = new ComponentName(context.getPackageName(), 
       RegistrationIntentService.class.getName()); 
     // Start the service, keeping the device awake while it is launching. 
     startWakefulService(context, (intent.setComponent(comp))); 
     setResultCode(Activity.RESULT_OK); 
    } 
} 

它解決MI設備上而不是在聯想的設備我的問題。

感謝

+0

嗨。你見過這個[post](http://stackoverflow.com/q/39504805/4625829)的答案嗎? –

+0

[Android應用程序在多任務托盤停止時未收到Firebase通知]的可能重複(http://stackoverflow.com/questions/39504805/android-app-not-receiving-firebase-notification-when-app-是停止從多t) –

+0

@AL是的,我做了,但它不是我在找什麼。 –

回答

1

聯想手機使用的後臺任務殺手停止後臺應用程序,隱藏的勾去掉任務的殺手限制在應用程序菜單

+0

我可以以編程方式限制它嗎? –

0

在有MIUI設備,你可以要求用戶添加您的應用程序的自動啓動

private void addAppToAutoStartList() { 
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this); 
    alertDialogBuilder.setTitle("Warning!"); 
    alertDialogBuilder.setMessage("Please add this app to the Auto Start list of your device for better performance."); 
    alertDialogBuilder.setPositiveButton("Add", new DialogInterface.OnClickListener() { 
    @Override public void onClick(DialogInterface dialogInterface, int i) { 
    dialogInterface.dismiss(); 
    try { 
    AppPreferences.getInstance(HomeActivity.this).setMiSpecialSetting(true); 
    Intent intent = new Intent(); 
    intent.setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")); 
    startActivity(intent); 
    } catch (Exception e) { 
    Toast.makeText(HomeActivity.this, "Unable to add!", Toast.LENGTH_SHORT).show(); 
    } 
    } 
    }); 
    alertDialogBuilder.setNegativeButton("Ignore", new DialogInterface.OnClickListener() { 
    @Override public void onClick(DialogInterface dialog, int arg1) { 
    dialog.dismiss(); 
    } 
    }); 
    AlertDialog alertDialog = alertDialogBuilder.create(); 
    alertDialog.show(); 
} 

而且通過檢查製造商像

if(android.os.Build.MANUFACTURER.equalsIgnoreCase("xiaomi")) { addAppToAutoStartList(); 
} 
調用這個方法:在使用本手機的列表

結論: 1.通過這種方式,如果用戶將您的應用添加到自動啓動列表中,那麼您的應用將能夠毫無問題地獲得推送通知。 2.如果你有任何計劃的工作運行,那麼即使在一鍵清理之後,你仍然可以運行你的工作,但是有一個限制,你的工作將會運行,但不是根據你的時間和彈性,它會隨時被調用1天,下一次通話可能會在2天后到來,因此無法保證定期通話。但這是我現在看到的像MIUI這樣的定製操作系統的唯一方式。而且我已經在許多具有android 5至7的小米設備以及每個結果相同的地方測試了這一點。

相關問題