プッシュ通知についてはわかりません。私は学ぶことをしようとしています。しかし、私は理解していません。
サーバーシステムに 1 つのテーブル MySQL データベースがあります。テーブルに変更が加えられたら、Android モバイル アプリに通知を表示します。
誰でも提案を提供できますか?
プッシュ通知についてはわかりません。私は学ぶことをしようとしています。しかし、私は理解していません。
サーバーシステムに 1 つのテーブル MySQL データベースがあります。テーブルに変更が加えられたら、Android モバイル アプリに通知を表示します。
誰でも提案を提供できますか?
実際には最近、主にそのuプロジェクト内でFCMをプッシュ通知に使用しています....プッシュ通知を構築するための最良のリンク:リンク
プッシュ通知を実行する手順 - Firebase Cloud Messaging Tutorial for Android
アプリ側
ルート レベルの build.gradle ファイルに移動し、次のコードを追加します。
a. この行クラスパス「com.google.gms:google-services:3.0.0」を追加します
b. この行を追加 compile 'com.google.firebase:firebase-messaging:9.0.0'
プロジェクトを同期します。
MyFirebaseInstanceIDService.java という名前のクラスを作成し、次のコードを記述します。
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
@Override
public void onTokenRefresh() {
//Getting registration token
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
//Displaying token on logcat
Log.d(TAG, "Refreshed token: " + refreshedToken);
}
private void sendRegistrationToServer(String token) {
//You can implement this method to store the token on your server
//Not required for current project
}
}
MyFirebaseMessagingService.java を作成し、次のコードを記述します。
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
/**
*
*/
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//Displaying data in log
//It is optional
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
//Calling method to generate notification
sendNotification(remoteMessage.getNotification().getBody());
}
//This method is only generating push notification
//It is same as we did in earlier posts
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Firebase Push Notification")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
AndroidManifest.xml ファイルで上記のサービスを定義する必要があります。したがって、マニフェストに移動して、次のように変更します。
<!-- Adding Internet Permission -->
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
Defining Services
-->
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
</application>
最後に
firebase コンソールに移動し、作成したアプリを選択します。左側のメニューから [通知] を選択します。新しいメッセージをクリックします。メッセージを入力し、単一のデバイスを選択して、コピーしたトークンを貼り付け、[送信] をクリックします。ビデオで行ったのと同じように、デバイスを確認します
これについての良い説明があります:
http://quickblox.com/developers/SimpleSample-messages_users-android
全体的な手順は次のとおりです。
ここにすべてを詳細に書くことはできません。すべてのステップで Google を使用します。
まず、Google プッシュ通知は GCM (Google Cloud Messaging) と呼ばれます。間違った名前を使用すると、間違った情報やチュートリアルにつながる可能性があります。もう 1 つは、Developer に頼る必要があります。この場合は、Google Developers の Web サイトから始めてください。そこには、基本的な情報とコード例のほとんどが掲載されています。https://developers.google.com/cloud-messaging/ .
Firebaseをチェックアウトできます...このリンクをチェックしてください
https://firebase.google.com/docs/cloud-messaging/
このリンクは、プッシュ通知について学ぶのに十分です
また、データベースのデータが変更されたときに通知を送信する場合は、API から FCM サーバーにリクエストを送信して、必要なデータをクライアントに配信します。