この文書の現在のバージョンと選択したバージョンの差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
android:androidstudio2で始めるアプリ開発入門 [2019/10/19 10:19] ips [startForegroundService] |
android:androidstudio2で始めるアプリ開発入門 [2019/12/01 09:11] (現在) ips |
||
---|---|---|---|
ライン 430: | ライン 430: | ||
[[https://qiita.com/gksdyd88/items/30df1f220001fad69d9e|Android Oreoでサービスを使ってみる]] | [[https://qiita.com/gksdyd88/items/30df1f220001fad69d9e|Android Oreoでサービスを使ってみる]] | ||
[[https://qiita.com/naoi/items/03e76d10948fe0d45597|Foreground Serviceの基本]] | [[https://qiita.com/naoi/items/03e76d10948fe0d45597|Foreground Serviceの基本]] | ||
+ | [[https://qiita.com/nukka123/items/791bc4f9043764789ee6|Android Oからのバックグラウンド・サービスの制限事項を実演する。]] | ||
+ | [[https://www.muaaru.com/2018/11/17/post-254/|[Android]バックグラウンドでセンサーなどのログを取得し続けるには]] | ||
+ | |||
+ | [[https://developer.android.com/about/versions/oreo/background|バックグラウンド実行制限]] | ||
+ | [[https://developer.android.com/about/versions/oreo/background-location-limits|バックグラウンド位置情報の制限]] | ||
Foreground(=前)Service(バックグラウンド)と思っていたので矛盾を感じていた。 | Foreground(=前)Service(バックグラウンド)と思っていたので矛盾を感じていた。 | ||
ライン 466: | ライン 471: | ||
Network:位置情報の精度は落ちるが、電力消費が少ない。屋内でも取得できる | Network:位置情報の精度は落ちるが、電力消費が少ない。屋内でも取得できる | ||
+ | ==== Parameter 'xxxx' is never used ==== | ||
+ | {{:kotlin:pasted:20191019-105034.png}} | ||
+ | ↓ | ||
+ | <code kotlin> | ||
+ | fun onMapShowCurrentButtonClick(@Suppress("UNUSED_PARAMETER")vieie: View){ | ||
+ | val uriStr="geo:${latitude},${longitude}" | ||
+ | val uri=Uri.parse(uriStr) | ||
+ | val intent = Intent(Intent.ACTION_VIEW,uri) | ||
+ | startActivity(intent) | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ==== ユーザー許可を取得する ==== | ||
+ | |||
+ | <code> | ||
+ | override fun onCreate(savedInstanceState: Bundle?) { | ||
+ | super.onCreate(savedInstanceState) | ||
+ | setContentView(R.layout.activity_main) | ||
+ | |||
+ | val locationManager=getSystemService(Context.LOCATION_SERVICE)as LocationManager | ||
+ | |||
+ | // 位置情報のユーザー許可を確認 | ||
+ | if (ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION ) | ||
+ | != PackageManager.PERMISSION_GRANTED | ||
+ | ) { | ||
+ | // 許可がなければ許可を求める | ||
+ | val permissions = arrayOf<String>(Manifest.permission.ACCESS_FINE_LOCATION) | ||
+ | ActivityCompat.requestPermissions(this, permissions, 1000) | ||
+ | // 求めた結果はonRequestPermissionsResult | ||
+ | return | ||
+ | } | ||
+ | |||
+ | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0L,0F,GPSLocationListener()) | ||
+ | |||
+ | } | ||
+ | |||
+ | // パーミッション許可を求めた結果 | ||
+ | override fun onRequestPermissionsResult( | ||
+ | requestCode: Int, | ||
+ | permissions: Array<out String>, | ||
+ | grantResults: IntArray | ||
+ | ) { | ||
+ | super.onRequestPermissionsResult(requestCode, permissions, grantResults) | ||
+ | |||
+ | if (requestCode==1000 && grantResults[0]==PackageManager.PERMISSION_GRANTED){ | ||
+ | |||
+ | //パーミッションが許可された場合 | ||
+ | val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager | ||
+ | val locationListener = GPSLocationListener() | ||
+ | |||
+ | // パーミッション許可を求めた結果を確認しているので不要に思えるが、 | ||
+ | // ↓ locationManager.requestLocationUpdates を呼ぶ前にかならず必要なだけ | ||
+ | if (ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){ | ||
+ | return | ||
+ | } | ||
+ | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0L,0F,locationListener) | ||
+ | |||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | </code> | ||
===== 第16回.Androidのマテリアルデザイン ~マテリアルデザインとツールバー~ ===== | ===== 第16回.Androidのマテリアルデザイン ~マテリアルデザインとツールバー~ ===== | ||