Ответ 1
Хорошо, я нашел решение.
Это json, который я отправляю с сервера в приложение
{
"registration_ids": [
"XXX",
...
],
"data": {
"id_offer": "41"
},
"notification": {
"title": "This is the Title",
"text": "Hello I'm a notification",
"icon": "ic_push",
"click_action": "ACTIVITY_XPTO"
}
}
В AndroidManifest.xml
<activity
android:name=".ActivityXPTO"
android:screenOrientation="sensor"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="ACTIVITY_XPTO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Когда приложение закрыто или находится в фоновом режиме, и пользователь нажимает на уведомление, он открывает мой ActivityXPTO, для получения id_offer мне нужно только
public class ActivityXPTO extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
String idOffer = "";
Intent startingIntent = getIntent();
if (startingIntent != null) {
idOffer = startingIntent.getStringExtra("id_offer"); // Retrieve the id
}
getOfferDetails(id_offer);
}
...
}
Что это...