내 webview Android 앱에 대한 firebase 푸시 알림을 설정하려고합니다. 내 목표는 알림에 URL을 보내고 앱에서 열 것입니다. 여기 내 문제가있다. 다음앱이 배경에있는 동안 Firebase 푸시 알림 데이터 처리
는메시지
<?php
// API access key from Google API's Console
define('API_ACCESS_KEY', 'XXXXX');
$id='XXXXXX';
$registrationIds = array($id);
// prep the bundle
$msg = array
(
'body' => 'Your post has received a reply',
'title' => 'Title of the post here',
);
$data = array
(
'url'=>'http://XXXXXXXX.com/forum/viewtopic.php?f=2&p=21421#p21421'
);
$fields = array
(
'registration_ids' => $registrationIds,
'notification' => $msg,
'data' => $data
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send');
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
에게 보낼 사용하여 PHP 코드 메신저입니다 그리고 이것은 내 매니페스트
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity" android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MyFirebaseMessagingService$NotificationBar" />
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name=".FirebaseIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
</application>
이며,이 내가 통과 여기에서 내 수신기
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
public static String url;
public static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Data: " + remoteMessage.getData());
url = remoteMessage.getData().get("url");
Log.d(TAG, "URL: " + url);
}
public class NotificationBar extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification_bar);
}
}
}
입니다 주 활동에 대한 URL. 이제 문제는 앱이 포 그라운드에 있고 메시지를 보내는 경우 로그의 URL을 볼 수 있다는 것입니다. 그러나 앱이 백그라운드에서 메시지를 보내면 상태의 알림 만 로그에 표시됩니다. 알림을 탭하면 url을 전달하지 않고 앱을 엽니 다.
도와 주시겠습니까? 제발 안드로이드 프로그래밍에 대해 거의 제로 아이디어를 가지고 가능한 한 자세하게하십시오.
감사합니다.
마법처럼 일했다 . 고마워요! – shahriar