忍者ブログ
  • 2024.04
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 2024.06
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

【2024/05/19 07:51 】 |
AndroidのIntent
Intentには設定できるプロパティがいろいろある。

action Intent.ACTION_VIEWなど
data
type MIME data type とか
class Intent呼び出し時に使用するクラスを指定。そのクラスは onReceive(Context, Intent) メソッドをオーバーライドしていて、その中でextraなどを取得して処理を行う
category Actionの振る舞いを明確にする。Intent.CATEGORY_BROWSABLEなど
flag 呼び出される側の起動する振る舞い。例えばバックグラウンドで呼び出される場合はIntent.FLAG_FROM_BACKGROUND
extra 付加情報。例えばIntent.EXTRA_TEXTを使えば、twitterクライアントを起動したとき、本文として表示させたいテキストなどをセットする




参考



Intent i = new Intent(getApplicationContext(), LocalNotificationReceiver.class);
i.putExtra("notification_id", tag);
i.putExtra("message", message);

PendingIntent sender = PendingIntent.getBroadcast(this, tag, i, PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);



PendingIntentは時間差でIntentを作るクラス。
calendar には起動させたい時刻が入っているとする。

LocalNotificationReceiver というクラスに onReceive() メソッドが定義されている。
これによってローカル通知が実装できることになる。


PR
【2015/02/03 14:13 】 | Android | 有り難いご意見(0)
<<新しいプロジェクトを新しいgitリポジトリで作るまでの手順 | ホーム | Androidでtwitterにテキストと画像を投稿(Intent)>>
有り難いご意見
貴重なご意見の投稿














<<前ページ | ホーム | 次ページ>>