前提・実現したいこと
android studioで登録地点に近づくとプッシュ通知で
お知らせされるアプリを作りたいと思っています。
(例 事故が多い交差点に差し掛かると通知が来るようなもの)
最近android studioをインストールしたばかりの初心者の為、本を片手に動かしている状態です。
試したこと
以下のサイトを参考にしたのですが、バージョンが違うのかエラーが多発してしまいました。
https://dev.classmethod.jp/smartphone/android/android-google-play-services-location-api-geofencing/
補足情報(FW/ツールのバージョンなど)
android studio 3.1.3 for Windows 64-bit
前提・実現したいこと
android studioで登録地点に近づくとプッシュ通知で
お知らせされるアプリを作りたいと思っています。
(例 事故が多い交差点に差し掛かると通知が来るようなもの)
最近android studioをインストールしたばかりの初心者の為、本を片手に動かしている状態です。
発生している問題・エラーメッセージ
Error:(11, 37) エラー: パッケージcom.google.android.gms.commonは存在しません Error:(13, 39) エラー: パッケージcom.google.android.gms.locationは存在しません Error:(23, 13) エラー: シンボルを見つけられません シンボル: クラス LocationClient 場所: クラス MainActivity Error:(70, 37) エラー: パッケージGooglePlayServicesClientは存在しません
試したこと
package com.example.shi.geofencing; import android.app.PendingIntent; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesClient; import com.google.android.gms.location.Geofence; import com.google.android.gms.location.LocationClient; import java.util.ArrayList; public class MainActivity extends FragmentActivity { private final MainActivity self = this; private LocationClient mLocationClient; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // LocationClient の生成 mLocationClient = new LocationClient(this, mConnectionCallbacks, mOnConnectionFailedListener); mLocationClient.connect(); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); int transitionType = LocationClient.getGeofenceTransition(intent); int color = transitionType == Geofence.GEOFENCE_TRANSITION_ENTER ? Color.GREEN : Color.RED; findViewById(android.R.id.content).setBackgroundColor(color); } private void addGeofence() { // Geofence の作成 // 緯度 double latitude = 35.697239; // 経度 double longitude = 139.774719; // 半径(メートル) float radius = 100; Geofence.Builder builder = new Geofence.Builder(); builder.setRequestId("classmethod_fence"); builder.setCircularRegion(latitude, longitude, radius); builder.setExpirationDuration(Geofence.NEVER_EXPIRE); builder.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT); ArrayList<Geofence> geofences = new ArrayList<Geofence>(); geofences.add(builder.build()); // PendingIntent の生成 Intent intent = new Intent(self, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // Geofences の登録 mLocationClient.addGeofences(geofences, pendingIntent, mOnAddGeofencesResultListener); } /** * 接続時・切断時のコールバック. */ private GooglePlayServicesClient.ConnectionCallbacks mConnectionCallbacks = new GooglePlayServicesClient.ConnectionCallbacks() { @Override public void onConnected(Bundle bundle) { Toast.makeText(self, "onConnected", Toast.LENGTH_LONG).show(); // Geofenceを登録 addGeofence(); } @Override public void onDisconnected() { Toast.makeText(self, "onDisconnected", Toast.LENGTH_LONG).show(); } }; /** * 接続失敗時のコールバック. */ private GooglePlayServicesClient.OnConnectionFailedListener mOnConnectionFailedListener = new GooglePlayServicesClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult connectionResult) { Toast.makeText(self, "onConnectionFailed", Toast.LENGTH_LONG).show(); } }; /** * Geofenceを登録したときのコールバック. */ private LocationClient.OnAddGeofencesResultListener mOnAddGeofencesResultListener = new LocationClient.OnAddGeofencesResultListener() { @Override public void onAddGeofencesResult(int i, String[] strings) { Toast.makeText(self, "onAddGeofencesResult", Toast.LENGTH_LONG).show(); } }; }
補足情報(FW/ツールのバージョンなど)
android studio 3.1.3 for Windows 64-bit