{"id":542,"date":"2018-11-04T14:36:44","date_gmt":"2018-11-04T05:36:44","guid":{"rendered":"http:\/\/www.typea.info\/blog\/index.php\/2018\/11\/04\/android_kotlin\/"},"modified":"2018-11-04T14:36:44","modified_gmt":"2018-11-04T05:36:44","slug":"android_kotlin","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2018\/11\/04\/android_kotlin\/","title":{"rendered":"Android Kotlin \u901a\u77e5\u30b5\u30f3\u30d7\u30eb"},"content":{"rendered":"<ul>\n<li>Android 8.0 \u4ee5\u964d\u3067\u901a\u77e5\u3092\u307e\u3068\u3081\u308b(\u4ee5\u524d\u3067\u306f\u307e\u3068\u3081\u306a\u3044)<\/li>\n<li>\u901a\u77e5\u30af\u30ea\u30c3\u30af\u3067\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u3092\u8d77\u52d5\u3059\u308b<\/li>\n<\/ul>\n<h3>Android 8.0<\/h3>\n<p>\u901a\u77e5\u304c\u307e\u3068\u307e\u3063\u3066\u3044\u308b<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/194255577d32_C906\/android_notification_group01.png\"><img loading=\"lazy\" decoding=\"async\" width=\"216\" height=\"381\" title=\"android_notification_group01\" style=\"display: inline; background-image: none;\" alt=\"android_notification_group01\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/194255577d32_C906\/android_notification_group01_thumb.png\" border=\"0\"><\/a><\/p>\n<p>\u901a\u77e5\u3092\u5c55\u958b<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/194255577d32_C906\/android_notification_group02.png\"><img loading=\"lazy\" decoding=\"async\" width=\"217\" height=\"383\" title=\"android_notification_group02\" style=\"display: inline; background-image: none;\" alt=\"android_notification_group02\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/194255577d32_C906\/android_notification_group02_thumb.png\" border=\"0\"><\/a><\/p>\n<h3>Android5.0<\/h3>\n<p>\u901a\u77e5\u306f\u307e\u3068\u307e\u3089\u306a\u3044<\/p>\n<p><a href=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/194255577d32_C906\/android_notification_group03.png\"><img loading=\"lazy\" decoding=\"async\" width=\"216\" height=\"381\" title=\"android_notification_group03\" style=\"display: inline; background-image: none;\" alt=\"android_notification_group03\" src=\"https:\/\/www.typea.info\/blog\/wp-content\/uploads\/image\/194255577d32_C906\/android_notification_group03_thumb.png\" border=\"0\"><\/a><\/p>\n<h3>\u30b5\u30f3\u30d7\u30eb<\/h3>\n<h3><\/h3>\n<pre class=\"prettyprint linenums\">private var mNotificationNumber = 0\r\n\/**\r\n * \u901a\u77e5\r\n * @see http:\/\/android.techblog.jp\/archives\/7976103.html\r\n * @see https:\/\/developer.android.com\/guide\/topics\/ui\/notifiers\/notifications?hl=ja\r\n * @see https:\/\/developer.android.com\/training\/notify-user\/build-notification\r\n * @see https:\/\/developer.android.com\/training\/notify-user\/channels\r\n * @see https:\/\/developer.android.com\/training\/notify-user\/group?hl=ja#create_a_group_and_add_a_notification_to_it\r\n * @see https:\/\/qiita.com\/mstssk\/items\/14e1b94be6c52af3a0a6\r\n * @see https:\/\/qiita.com\/naoi\/items\/367fc23e55292c50d459\r\n * @see https:\/\/www.gaprot.jp\/pickup\/old-tips\/android-o\/notification-channel\r\n *\/\r\nprivate fun notification() {\r\n    val channelId = \"channelId\"\r\n    val channelName = \"GcpApiTrial\"\r\n    val groupKey = \"groupKey\"\r\n    val notifyId = ++mNotificationNumber;\r\n\r\n    val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager\r\n\r\n    if (android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.O) {\r\n        \/\/ \u901a\u77e5\u30c1\u30e3\u30cd\u30eb\u306e\u767b\u9332\r\n        \/\/ targetSdkVersion(26 Oreo) \u4ee5\u964d\u306e\u5834\u5408\u3001\u901a\u77e5\u30c1\u30e3\u30cd\u30eb\u3092\u4f7f\u7528\u3057\u306a\u3044\u3068\u901a\u77e5\u304c\u8868\u793a\u3055\u308c\u306a\u3044\r\n        \/\/ \u8907\u6570\u306e\u30c1\u30e3\u30f3\u30cd\u30eb\u3092\u4f5c\u308a\u3001\u500b\u3005\u306e\u901a\u77e5\u3092\u4efb\u610f\u306e\u30c1\u30e3\u30f3\u30cd\u30eb\u306b\u5272\u308a\u632f\u308b\u3053\u3068\u306b\u3088\u3063\u3066\u3001\r\n        \/\/ \u91cd\u8981\u5ea6\u3084\u901a\u77e5\u97f3\u306a\u3069\u306e\u5c5e\u6027\u3092\u4e00\u62ec\u3067\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\r\n        val summaryId = 0\r\n        if (manager.getNotificationChannel(channelId) == null) {\r\n            val channel = NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT)\r\n            channel.apply {\r\n                description = \"GcpApiTrial Notification\"\r\n            }\r\n            manager.createNotificationChannel(channel)\r\n        }\r\n        val summary = NotificationCompat.Builder(this, channelId).run {\r\n            setContentTitle(\"Summary Content Title\")\r\n            setContentText(\"New Message.\")\r\n            setSmallIcon(R.drawable.ic_menu_camera)\r\n            setStyle(NotificationCompat.InboxStyle().addLine(\"New Message Add line\"))\r\n            setNumber(mNotificationNumber)\r\n            setGroup(groupKey)\r\n            setGroupSummary(true)\r\n            build()\r\n        }\r\n        manager.apply {\r\n            notify(summaryId, summary)\r\n        }\r\n    }\r\n\r\n    \/\/ \u901a\u77e5\u30af\u30ea\u30c3\u30af\u3067\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u3092\u8d77\u52d5\r\n    val intent = Intent(this, MainActivity::class.java)\r\n    val stackBuilder = TaskStackBuilder.create(this)\r\n    stackBuilder.addParentStack(MainActivity::class.java)\r\n    stackBuilder.addNextIntent(intent)\r\n    val pendingIntent = stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT)\r\n\r\n    \/\/ \u901a\u77e5\u306e\u4f5c\u6210\r\n    val notification = NotificationCompat.Builder(this, channelId).run {\r\n        setContentTitle(\"New Message\")\r\n        setContentText(\"You've received new message. No.$mNotificationNumber\")\r\n        setSmallIcon(R.drawable.ic_menu_camera)\r\n        setNumber(mNotificationNumber)\r\n        setContentIntent(pendingIntent)\r\n        setAutoCancel(true) \/\/ \u901a\u77e5\u30af\u30ea\u30c3\u30af\u3067\u30af\u30ea\u30a2\r\n        setGroup(groupKey)\r\n        build()\r\n    }\r\n    manager.apply {\r\n        notify(notifyId, notification)\r\n    }\r\n}\r\n<\/pre>\n<h3>\u53c2\u8003<\/h3>\n<p><a href=\"http:\/\/android.techblog.jp\/archives\/7976103.html\">http:\/\/android.techblog.jp\/archives\/7976103.html<\/a><br \/>\n<a href=\"https:\/\/developer.android.com\/guide\/topics\/ui\/notifiers\/notifications?hl=ja\">https:\/\/developer.android.com\/guide\/topics\/ui\/notifiers\/notifications?hl=ja<\/a><br \/>\n<a href=\"https:\/\/developer.android.com\/training\/notify-user\/build-notification\">https:\/\/developer.android.com\/training\/notify-user\/build-notification<\/a><br \/>\n<a href=\"https:\/\/developer.android.com\/training\/notify-user\/channels\">https:\/\/developer.android.com\/training\/notify-user\/channels<\/a><br \/>\n<a href=\"https:\/\/developer.android.com\/training\/notify-user\/group?hl=ja#create_a_group_and_add_a_notification_to_it\">https:\/\/developer.android.com\/training\/notify-user\/group?hl=ja#create_a_group_and_add_a_notification_to_it<\/a><br \/>\n<a href=\"https:\/\/qiita.com\/mstssk\/items\/14e1b94be6c52af3a0a6\">https:\/\/qiita.com\/mstssk\/items\/14e1b94be6c52af3a0a6<\/a><br \/>\n<a href=\"https:\/\/qiita.com\/naoi\/items\/367fc23e55292c50d459\">https:\/\/qiita.com\/naoi\/items\/367fc23e55292c50d459<\/a><br \/>\n<a href=\"https:\/\/www.gaprot.jp\/pickup\/old-tips\/android-o\/notification-channel\">https:\/\/www.gaprot.jp\/pickup\/old-tips\/android-o\/notification-channel<\/a>\n<\/p>\n<p><a href=\"https:\/\/www.amazon.co.jp\/Android%E3%82%A2%E3%83%97%E3%83%AA%E9%96%8B%E7%99%BA%E3%81%AE%E6%A5%B5%E6%84%8F-%E3%83%97%E3%83%AD%E5%93%81%E8%B3%AA%E3%82%92%E5%AE%9F%E7%8F%BE%E3%81%99%E3%82%8B%E3%81%9F%E3%82%81%E3%81%AE%E7%8F%BE%E5%A0%B4%E3%81%AE%E7%9F%A5%E6%81%B5%E3%81%A8%E3%83%86%E3%82%AF%E3%83%8B%E3%83%83%E3%82%AF-%E6%9C%A8%E7%94%B0-%E5%AD%A6\/dp\/4774188174\/ref=as_li_ss_il?s=books&amp;ie=UTF8&amp;qid=1541309310&amp;sr=1-14&amp;keywords=kotlin&amp;linkCode=li2&amp;tag=typea09-22&amp;linkId=2bcc40a9fbf8554c47515535a7b76fee\" target=\"_blank\"><img decoding=\"async\" src=\"\/\/ws-fe.amazon-adsystem.com\/widgets\/q?_encoding=UTF8&amp;ASIN=4774188174&amp;Format=_SL160_&amp;ID=AsinImage&amp;MarketPlace=JP&amp;ServiceVersion=20070822&amp;WS=1&amp;tag=typea09-22\" border=\"0\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"1\" height=\"1\" style=\"margin: 0px !important; border: currentcolor !important; border-image: none !important;\" alt=\"\" src=\"https:\/\/ir-jp.amazon-adsystem.com\/e\/ir?t=typea09-22&amp;l=li2&amp;o=9&amp;a=4774188174\" border=\"0\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Android 8.0 \u4ee5\u964d\u3067\u901a\u77e5\u3092\u307e\u3068\u3081\u308b(\u4ee5\u524d\u3067\u306f\u307e\u3068\u3081\u306a\u3044) \u901a\u77e5\u30af\u30ea\u30c3\u30af\u3067\u30a2\u30af\u30c6\u30a3\u30d3\u30c6\u30a3\u3092\u8d77\u52d5\u3059\u308b Android 8.0 \u901a\u77e5\u304c\u307e\u3068\u307e\u3063\u3066\u3044\u308b \u901a\u77e5\u3092\u5c55\u958b Android5.0 \u901a\u77e5\u306f\u307e\u3068\u307e\u3089\u306a\u3044 \u30b5\u30f3\u30d7\u30eb p [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[39,105],"tags":[],"class_list":["post-542","post","type-post","status-publish","format-standard","hentry","category-android","category-kotlin"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=542"}],"version-history":[{"count":0,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/542\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}