0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

コマンド(curl)でPushテストする方法(Android)

Posted at

メモ書き

iOSに続き、Androidでもテストが必要になったのでメモします。
必要な方はご参考ください。

事前作業

  • Serverkey取得

Firebaseコンソールから確認できます。
スクリーンショット 2020-03-27 13.23.49.png

  • token取得

FirebaseInstanceId.getInstance().instanceId
        .addOnCompleteListener(OnCompleteListener { task ->
            if (!task.isSuccessful) {
                Log.w(TAG, "getInstanceId failed", task.exception)
                return@OnCompleteListener
            }

            // Get new Instance ID token
            val token = task.result?.token

            // Log and toast
            val msg = getString(R.string.msg_token_fmt, token)
            Log.d(TAG, msg)
            Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
        })

スクリプト

push_test.sh
# !/bin/bash
token='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxWmdyQhVDolOSTp_XRjmv'
server_key='AAAAjfX2vXY:APxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

read -r -d '' payload <<-'EOF'
{
     "title":"ホゲホゲ",
     "body":"hugahuga"
}
EOF

echo $payload

curl \
    --header "Authorization: key=${server_key}" \
    --header Content-Type:"application/json" \
    https://fcm.googleapis.com/fcm/send \
    -d "{
        \"to\" : \"${token}\",
        \"data\": $payload
    }"

実行

下記のスクリプト叩くだけ

/bin/bash push_test.sh

以上。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?