質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

2758閲覧

Unity)ローカルプッシュ通知

navesanta

総合スコア198

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

1クリップ

投稿2019/05/30 09:44

Unityで無料で使えるローカルプッシュ通知(レビュー版)が結構進化していて使い勝手が
良くなってきたので実装して色々試しています。

Unityモバイル通知
(翻訳すると分かりやすい)

できること)
・アプリ内に実装して時間を設定するとプッシュ通知が届く。
・アプリを完全終了しても設定しているプッシュ通知が届く・
・表示アイコンを設定できる。
・プッシュ通知をタップすると設定したアクションを起こせる※

質問は※の部分でマニュアルを見ると下記の様な設定をするとIntentのようにnotificationに保存することが
できデータを渡せるとのことですが

 var notification = new AndroidNotification(); notification.IntentData = "{\"title\": \"Notification 1\", \"data\": \"200\"}";

上のコードで設定したものをタップ時に取得するコードがよく分かりません。(サンプルに見当たらない)
(Jsonデータを取得しているような?)
分かる方教えてください。

コード全文

using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.UI; using Unity.Notifications.Android; public class LocalNotification : MonoBehaviour { int setTime; int nowTime; int seconds; int activeHour; int activeMin; int activeFlag; int activeSeconds; int cateId; string title; string message; string prefskeyHour; string prefskeyMin; string prefskeyActive; public Text identifierText; public Text idText; public Text channelText; public Text notificationText; // var identifier; string m_channelId = "english"; // Start is called before the first frame update void Start() { //通知用のチャンネルを作成する var c = new AndroidNotificationChannel { Id = m_channelId, Name = "hogehog", Importance = Importance.High, Description = "説明する", }; AndroidNotificationCenter.RegisterNotificationChannel(c); } void OnApplicationPause(bool pauseStatus) { uniNotification("タイトル", "message", 30); } public void uniNotification(string title, string message, int seconds){ var notification = new AndroidNotification(); notification.Title = title; notification.Text = message; notification.IntentData = "{\"title\": \"Notification 1\", \"data\": \"200\"}"; notification.FireTime = DateTime.Now.AddSeconds(seconds); // if( CheckScheduledNotificationStatus(identifier) == NotificationStatus.Scheduled) // { // UpdateScheduleNotification(identifier, newNotification); // } else if( CheckScheduledNotificationStatus(identifier) == NotificationStatus.Unkown) // { //識別子を割り当てる var identifier = AndroidNotificationCenter.SendNotification(notification, m_channelId); identifierText.text = identifier.ToString(); // } //受信したNotificationをタップした時に取得するデータ var notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent(); if(notificationIntentData != null) { var id = notificationIntentData.Id; var channel = notificationIntentData.Channel; var notificationValue = notificationIntentData.Notification; idText.text = id.ToString(); channelText.text = channel; notificationText.text = notificationValue.ToString(); // return notification.IntentData; } } int TimeChangedScript(int hour, int min) { DateTime now = DateTime.Now; int nowHour = now.Hour; int nowMinute = now.Minute; setTime = hour * 60 + min; nowTime = nowHour * 60 + nowMinute; if(setTime > nowTime){ seconds = (setTime - nowTime) * 60; }else{ seconds = (1440 + setTime - nowTime) * 60; //1440 = 24 * 60:時間を分にして加算 } return seconds; } }

フォーラムもあり、本当はそちらで質問するべきなのかもしれませんが
英語のやりとりのため、読むことはできますがそちらで質問するのには自信がありません。
また疑問に思っている事のやりとりはフォーラムには見当たりません。

よろしくお願いします。

環境)
PC: mac
Unity2018.2
言語:C#

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

何度も読んで確認したところ
「IntentDataプロパティを設定することで、通知オブジェクトに任意の文字列データを格納」
ということは
notification.IntentData = 文字列データA;
と単純にString型のデータで設定してみたところ
var notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent();
の後に
var notificationStringValue = notification.IntentData;
で取得できました。

投稿2019/06/01 02:22

navesanta

総合スコア198

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問