2016-02-19 76 views
-1

我正嘗試在我的應用中使用推送通知。我從服務推送通知的站點複製並粘貼示例代碼。當我發送推送時,推送只會發送到我的電話和模擬器,而不會發送到安裝在它們上的所有應用。 如果代碼有問題,爲什麼我的手機收到推送?如果沒有,爲什麼其他手機不能接收? (我可以正確看到有多少用戶在我的面板中安裝了該應用程序。)Android推送通知不適用於某些電話

您的想法出了什麼問題?

你可以在下面看到我的密碼。

接收機類:

public class myReceiver extends BroadcastReceiver { 
@Override 
public void onReceive(Context context, Intent intent) { 
    long reqId= intent.getLongExtra("RequestId", -1); 
    String msg = intent.getStringExtra("Message"); 

    Toast.makeText(context, msg, Toast.LENGTH_LONG).show(); 

}} 

myApplicaton類別:

public class myApplicaton extends SlsApplication implements IFinishedInit { 
@Override 
public void onCreate() { 
    super.onCreate(); 

    String sid = "f4439879-8bc1-4c01-87ce-8e98d0f76ccc"; 

    SLS.init(this,sid,this); 

} 

@Override 
public void finishedInit(int i) { 
    switch (i){ 
     case SLS.RESULT_OK: 
      Log.i("baas", "RESULT_OK"); 
      break; 
     case SLS.RESULT_FAILED: 
      Log.i("baas", "RESULT_FAILED"); 
      break;} 
    } 
} 

清單:

<?xml version="1.0" encoding="utf-8"?> 

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="com.example.pushnotif.permission.C2D_MESSAGE" /> 

<permission android:name="com.example.pushnotif.permission.C2D_MESSAGE" 
    android:protectionLevel="signature" /> 


<application 
    android:name=".myApplicaton" 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme.NoActionBar"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <receiver android:name="ir.sls.android.slspush.Receiver.GcmBroadcastReceiver" 
     android:permission="com.google.android.c2dm.permission.SEND"> 

     <intent-filter> 
      <action android:name="com.google.android.c2dm.intent.RECEIVE" /> 
      <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> 
      <category android:name="com.example.pushnotif" /> 
     </intent-filter> 
    </receiver> 
    <service android:name="ir.sls.android.slspush.GcmIntentService" /> 

    <receiver android:name="ir.sls.android.slspush.NetWatcher"> 
     <intent-filter> 
      <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> 
     </intent-filter> 
    </receiver> 

    <receiver android:name=".myReceiver" > 
     <intent-filter> 
      <category android:name="com.example.pushnotif" /> 
      <action android:name="ir.sls.android.slspush.ActionSlsPushReceived" /> 
     </intent-filter> 
    </receiver> 
</application> 

+0

請發表您正在使用的代碼。如果不考慮您的潛在解決方案,我們無法提供正確的答案。 – abhi

回答

1

請檢查所有未接收的手機是否產生GCM事登記ID ..