Задача приложения звонить на указанный в push сообщении номер, даже если приложение в фоне. Все работает нормально, но в определенный момент, будь то через час или через сутки приложение перестаёт реагировать на push сообщения, даже если оно снова было открыто.
Само сообщение отправляю через curl:
$fields = array(
'to' => ($tokens),
'data' => array( "title" => "phone call", "body" => $phone_number),
'time_to_live' => (0),
);
Получение и отправка содержимого в activity:
MyFirebaseMessagingService:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
Bundle bundle = new Bundle();
bundle.putString("msgBody", remoteMessage.getData().toString());
Intent new_intent = new Intent();
new_intent.setAction("ACTION_STRING_ACTIVITY");
new_intent.putExtra("msg", bundle);
sendBroadcast(new_intent);
}
MainActivity:
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private BroadcastReceiver activityReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getBundleExtra("msg");
String messagePhone;
messagePhone = bundle.getString("msgBody");
String callOrder = messagePhone.replaceAll("\\D+","");
makeCall("tel:" + callOrder);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button logTokenButton = (Button) findViewById(R.id.logTokenButton);
Button HideAppButton = (Button) findViewById(R.id.buttonHideApp);
if (activityReceiver != null) {
IntentFilter intentFilter = new IntentFilter("ACTION_STRING_ACTIVITY");
registerReceiver(activityReceiver, intentFilter);
}
AndroidManifest:
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- [START firebase_service] -->
<service
android:name=".MyFirebaseMessagingService"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- [END firebase_service] -->
<!-- [START firebase_iid_service] -->
<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок
За два дня так и не смог подписать приложение с помощью pepkjar !
ПриветствуюЯ использую DialogFragment который вызывается из главного Activity, в самом DialogFragment я использую собственную разметку, в которой реализован...