Notificationをタップして確認のため画像を開くときに、標準のギャラリーで開きたいなと思って書いてみたコード。
protected void onPostExecute(String description) {
if (error) {
showNotification(DOWNLOAD_CANCELED,"Data download ended abnormally!", "", null);
} else {
//開いてみるだけなのでACTION_VIEWをセット
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("image/*");
//ターゲットの画像URIを設定
intent.setData(download_uri);
//PendingIntentを作成
PendingIntent contentIntent = PendingIntent.getActivity(myAppContext, 0, intent, 0);
//Notificationを表示
showNotification(DOWNLOAD_DONE, "Data download is complete!",description, contentIntent);
}
}
private void showNotification(int mode, String contentTitle,String contentText, PendingIntent contentIntent) {
Notification notification = null;
long now = System.currentTimeMillis();
switch (mode) {
case DOWNLOADING:
notification = new Notification(android.R.drawable.stat_sys_download, contentTitle, now);
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags = Notification.FLAG_ONGOING_EVENT;
break;
case DOWNLOAD_DONE:
notification = new Notification(android.R.drawable.stat_sys_download_done, contentTitle,now);
notification.flags = Notification.FLAG_AUTO_CANCEL;
break;
case DOWNLOAD_CANCELED:
notification = new Notification(android.R.drawable.ic_menu_close_clear_cancel,contentTitle, now);
notification.flags = Notification.FLAG_AUTO_CANCEL;
break;
}
notification.setLatestEventInfo(myAppContext, contentTitle,contentText, contentIntent);
notificationManager.notify(notification_id, notification);
}
Notificationをタップすると・・・
ダウンロード後の画像がギャラリーで開きます。
Notificationとギャラリーを絡めたサンプルがあまり見当たらなかったので忘備録としてメモメモ。

