2015-05-28 13 views
10

Próbuję skonfigurować powiadomienia wypychania parse na Androida od jakiegoś czasu. Podążyłem za różnymi samouczkami i próbuję wysyłać powiadomienia z ich platformy internetowej, ale nic nie działa. Oto, co próbowałem do tej pory.Analizowanie notatek na urządzeniu z systemem Android nie będzie działało.

Oto onCreate metoda mojej klasie Application

@Override 
    public void onCreate() { 
     super.onCreate(); 
     Log.i("PushNotifications","PARSE initialize"); 

     Parse.initialize(this, "******************************", "*****************************"); 
     ParseInstallation.getCurrentInstallation().saveInBackground(); 

     ParsePush.subscribeInBackground("", new SaveCallback() { 
      @Override 
      public void done(ParseException e) { 
       if (e == null) { 
        Log.i("PushNotifications","com.parse.push" + " successfully subscribed to the broadcast channel."); 
       } else { 
        Log.i("PushNotifications","com.parse.push" + " failed to subscribe for push"); 
       } 
      } 
     }); 

    } 

Nazywa się to z powodzeniem, jak dostać dziennik

powodzeniem subskrypcji do kanału transmisji.

Również tutaj jest kilka istotnych zawartość mojego pliku manifestu:

<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
<permission android:name="com.my.app.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
<uses-permission android:name="com.my.app.permission.C2D_MESSAGE" /> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> 
<uses-permission android:name="android.permission.VIBRATE" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.WAKE_LOCK" /> 
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 

<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
<uses-permission android:name="android.permission.READ_CONTACTS"/> 
<uses-permission android:name="android.permission.SEND_SMS" /> 
<uses-permission android:name="android.permission.CAMERA" /> 
<uses-feature android:name="android.hardware.camera" /> 


<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:name=".App" 
    android:theme="@style/AppTheme"> 

    <activity 
     android:name=".activities.MainActivity" 
     android:launchMode="standard" 
     android:screenOrientation="sensorPortrait"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <meta-data android:name="com.parse.push.gcm_sender_id" android:value="id:123456789" /> 
    <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/ic_launcher"/> 

    <service android:name="com.parse.PushService" /> 
    <receiver android:name="com.parse.ParseBroadcastReceiver"> 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      <action android:name="android.intent.action.USER_PRESENT" /> 
     </intent-filter> 
    </receiver> 
    <receiver android:name="com.parse.ParsePushBroadcastReceiver" 
     android:exported="false"> 
     <intent-filter> 
      <action android:name="com.parse.push.intent.RECEIVE" /> 
      <action android:name="com.parse.push.intent.DELETE" /> 
      <action android:name="com.parse.push.intent.OPEN" /> 
     </intent-filter> 
    </receiver> 
    <!--com.parse.GcmBroadcastReceiver"--> 
    <receiver android:name="com.parse.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.my.app" /> 
     </intent-filter> 
    </receiver> 

</application> 

gdy próbuję wysyłając impuls ze strony Analiza składni, nic się nie dzieje.

Ponieważ to nie działa, próbowałem wdrożyć własną GcmBroadcastReceiver i zmienić ją w manifeście.

<receiver android:name=".receivers.MyCustomReceiver" 
      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.my.app" /> 
      </intent-filter> 
</receiver> 

I

public class MyCustomReceiver extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.i("PushNotifications","MyCustomReceiver"); 
    } 
} 

bez powodzenia.

Potem próbowałem także stworzyć własny ParsePushBroadcastReceiver (przez dziedziczenie z ParsePushBroadcastReceiver).

<receiver android:name=".receivers.CustomParseReceiver" 
      android:exported="false"> 
      <intent-filter> 
       <action android:name="com.parse.push.intent.RECEIVE" /> 
       <action android:name="com.parse.push.intent.DELETE" /> 
       <action android:name="com.parse.push.intent.OPEN" /> 
      </intent-filter> 
</receiver> 

I

public class CustomParseReceiver extends ParsePushBroadcastReceiver { 

    @Override 
    protected Notification getNotification(Context context, Intent intent) { 
     Log.i("PushNotifications","PARSE getNotification"); 
     return null; 
    } 

    @Override 
    protected void onPushOpen(Context context, Intent intent) { 
     Log.i("PushNotifications","PARSE onPushOpen"); 
    } 

    @Override 
    protected void onPushReceive(Context context, Intent intent) { 
     Log.i("PushNotifications","PARSE onPushReceive");   
    } 

    private JSONObject getDataFromIntent(Intent intent) { 
     Log.i("PushNotifications","PARSE getDataFromIntent");    
    } 

} 

To nie działało.

Chodzi o to .. kiedy tworzę własny GCM BroadcastReceiver i wysyłam powiadomienie z mojego własnego serwera (z małym skryptem php), powiadomienie zostanie pomyślnie odebrane.

Naprawdę zastanawiam się, co jest nie tak z moją implementacją systemu powiadomień parsowania po stronie klienta.

Jakąkolwiek wskazówkę dotyczącą przyczyny problemu?

+0

Wypróbuj za pomocą 'android: exported =" true "' na odbiorniku rozgłoszeniowym – FunkTheMonk

+0

Zgłasza wyjątek SecurityException: Aby zapobiec zewnętrznym manipulacjom w powiadomieniach aplikacji, wszystkie zarejestrowane odbiorniki do obsługi poniższych działań muszą mieć ustawione eksportowane atrybuty na false : com.parse.push.intent.RECEIVE, com.parse.push.intent.OPEN, com.parse.push.intent.DELETE – AlexMok

+1

Twój kod wydaje się być w porządku. Myślę, że powinieneś sprawdzić błędy pisowni. Użyłem Parse i utknąłem przez 6 godzin, aby znaleźć błąd pisowni 'Player' 'Players'. – Mayank

Odpowiedz

2

pierwsze: czy włączyć ustawienia powiadomień push z projektu zachodzącego

I w obliczu tego samego problemu, w końcu mogę usunąć mój projekt i budowę nowego w Parse, to problem rozwiązany, nie robiąc żadnych innych rzeczy !!! ! Czemu ?? Nie wiem ...

i nie zapomnij dostać zawsze najnowszy Parse SDK, teraz jego Parse-1.9.2.jar

3

moje 2 centów na to (mam nadzieję, że to pomaga):

Miałem podobny problem, który postanowiłem (wyjaśnione Here), tak, że może być problem, jeśli nie, rzucić okiem na moje pliki na szybki rzut oka wydają się mieć jakąś małą różnicę od Ciebie, a one działają więc warto spojrzeć:

Oczywisty sekcja:

<!-- for parse pushes --> 
    <service android:name="com.parse.PushService" /> 

    <receiver android:name="com.parse.ParseBroadcastReceiver" > 
     <intent-filter> 
      <action android:name="android.intent.action.BOOT_COMPLETED" /> 
      <action android:name="android.intent.action.USER_PRESENT" /> 
     </intent-filter> 
    </receiver> 
    <receiver 
      android:name="com.MyStuff.stuff.utils.MyPushReceiver" 
      android:exported="false" > 
     <intent-filter> 
      <action android:name="com.parse.push.intent.RECEIVE" /> 
      <action android:name="com.parse.push.intent.OPEN" /> 
      <action android:name="com.parse.push.intent.DELETE" /> 
     </intent-filter> 
    </receiver> 
    <receiver 
      android:name="com.parse.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.MyStuff.stuff" /> 
     </intent-filter> 
    </receiver> 
    <meta-data 
      android:name="com.parse.push.notification_icon" 
      android:resource="@drawable/ic_launcher" /> 

i wdrożone moje własne ParsePushBroadcastReceiver:

public class MyPushReceiver extends ParsePushBroadcastReceiver 
{ 
    @Override 
    protected void onPushOpen(Context context, Intent intent) 
    { 
    //bla bla... 
    } 

    @Override 
    protected void onPushReceive(Context context, Intent intent) 
    { 
    // bla bla... 
    } 

    @Override 
    protected Notification getNotification(Context context, Intent intent) 
    { 
     Notification notification = super.getNotification(context, intent); 
    // do some stuff with it.. 
    } 

} 

i moja klasa Zastosowanie:

public class MyApplication extends Application 
{ 

    private static final String CKey = "***********"; 
    private static final String AId = "************"; 

    @Override 
    public void onCreate() 
    { 
     super.onCreate(); 
     Parse.initialize(this, AId, CKey); 

     //initialized some stuff.. 

     ParsePush.subscribeInBackground("", new SaveCallback() 
     { 
      @Override 
      public void done(ParseException e) 
      { 
       if (null == e) 
       { 
        ParseInstallation install = ParseInstallation.getCurrentInstallation(); 
        String token = install.getString("deviceToken"); 
        //do some stuff with it... 
       } 
      } 
     }); 
     ParseInstallation.getCurrentInstallation().saveInBackground(); 
     //some more stuff 
    } 

Nadzieję ustawia cię na właściwej drodze!

+0

Dziękuję za odpowiedź Tommy. Skopiowałem twój kod i zastąpiłem go moim, niestety to nie rozwiązało tego problemu. O tokenie, który dostajesz z obiektu ParseInstallation, czy jest to ten sam token GCM, jak przy użyciu GoogleCloudMessaging.getInstance (context) .register()? – AlexMok

+0

AFAIK tak, pochodzi to z dokumentów parsowania: "deviceToken: wygenerowany przez Apple token używany na urządzeniach z iOS lub token używany przez GCM do śledzenia identyfikatora rejestracji (tylko do odczytu)", ale przeczytałbym o tym więcej w ich dokumenty :) – TommySM

Powiązane problemy