周辺デバイスへのデータ送信
周辺デバイスに対してのデータ送信方法を説明します。送信方法は以下の4種類があります。
-
Notification
- AndroidのNotificationに相当する内容を周辺デバイスへ通知することができます。
-
メール通知
- メールに関する内容を周辺デバイスへ通知します。
-
スケジュール通知
- スケジュールに関する内容を周辺デバイスへ通知します。
-
その他通知
- 複数のデータファイル、 画像、メディアを通知することができます。
Notification
SendNotificationクラスを利用することで、AndroidのNotification相当の内容(タイトル、本文)を周辺デバイスに通知することができます。その他、アイコン画像もあわせて通知できます。
import com.nttdocomo.android.sdaiflib.SendNotification;
public void sendNotify() {
SendNotification sendNotification = new SendNotification(getApplicationContext());
sendNotification.setText("本文");
sendNotification.setTitle("タイトル");
int resId = R.drawable.ic_notificaion; // アイコン画像のリソースID
sendNotification.setIcon(resId);
sendNotification.send();
}
メール通知
SendMailクラスを利用することで、メールに関する内容を周辺デバイスへ通知します。
タイトルや本文、送信者名、送信者のアドレスや受信時間を通知することができます。
マニフェストファイルにはメール通知利用の宣言を記載してください。
<application
~中略~
<meta-data
android:name="com.nttdocomo.android.smartdeviceagent.feature.mail_notification"
android:value="true" />
~中略~
</application>
import com.nttdocomo.android.sdaiflib.SendMail;
public void sendMail() {
SendMail sendMail = new SendMail(getApplicationContext());
sendMail.setTitle("タイトル");
sendMail.setText("本文");
sendMail.setSendUser("ユーザー");
String address = "xxxx@xxx.com";
sendMail.setAddress(address);
long receiveTime = Calendar.getInstance().getTimeInMillis(); // 受信日時(UNIXタイム)
sendMail.setReceiveTime(receiveTime);
sendMail.send();
}
スケジュール通知
SendScheduleクラスを利用することで、スケジュール情報を周辺デバイスへ通知します。
タイトル、本文、開始時間、終了時間、場所、人の情報、詳細、内容(3種類まで送信可能)を通知することができます。
import com.nttdocomo.android.sdaiflib.SendSchedule;
public void sendSchedule() {
SendSchedule sendSchedule = new SendSchedule(getApplicationContext());
long startTime = 1449810987; // 開始時間
long endTime = 1449813315; // 終了時間
sendSchedule.setStartTime(startTime);
sendSchedule.setEndTime(endTime);
sendSchedule.setTitle("タイトル");
sendSchedule.setWhere("場所");
sendSchedule.setPerson("人の情報");
sendSchedule.setDescription("詳細");
sendSchedule.setContent1(new byte[] {}); // 内容
sendSchedule.send();
}
その他通知
SendOtherクラスを利用することで、Notification、メール通知、スケジュールに当てはまらない、その他の情報を周辺デバイスに通知するときに使用します。
Notificationではタイトル、本文、アイコンを通知できるのに対し、その他通知では、複数のデータファイル、 画像、メディアを通知することができます。
import com.nttdocomo.android.sdaiflib.SendOther;
public void sendOther() {
SendOther sendOther = new SendOther(getApplicationContext());
int dataNo1 = 1; // contentの番号(1~10まで)
int dataNo2 = 2;
byte dataContent[] = new byte[] {};
sendOther.setContent(dataNo1, dataContent);
sendOther.setContentUri(dataNo2, "データのURI");
sendOther.setImageUri("画像のURI");
sendOther.setImageMime("画像のMIMEタイプ");
sendOther.setMediaUri("メディアのURI");
sendOther.setMediaMime("メディアのMIMEタイプ");
sendOther.send();
}

