안드로이드 폰에서
Google Play Services
OAuth, Authentication(인증)
구글 플레이 서비스는 항상 최신이어야 한다!
왜 안드로이드 2.2, 또는 그 이상버전이어야 하지?
Google Play Services
Android Support Library
지겹고 힘든일은 내가 대신한다(feat. 로케이션 팀)
private void connectLBS() {
int gpsExists = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (gpsExists == ConnectionResult.SUCCESS) {
mLocationClient = new LocationClient(this, this, this);
mLocationClient.connect();
}
}
@Override
private void onConnected(Bundle connectionHint) {
requestUpdates(mLocationClient);
}
LocationRequest request = LocationRequest.create();
request.setInterval(minTime);
request.setPriority(lowPowerMoreImporantThanAccuracy?
LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY :
LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationClient.requestLocationUpdates(request, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
updateLocation(location);
}
});
대신 다 일해주겠어
Fused Location Provider 의 장점
Intent intent = new Intent(this, ActivityRecognitionService.class);
intent.setAction(MyActivity.ACTION_STRING);
PendingIntent pi = PendingIntent.getService(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
mActivityRecognitionClient.requestActivityUpdate(interval, pi);
@Override
protected void onHandleIntent(Intent intent) {
if (intent.getAction() == MyActivity.ACTION_STRING) {
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
DetectedActivity detectedActivity = result.getMostProbableActivity();
int activityType = detectedActivity.getType();
if (activityType == DetectedActivity.STILL) {
setUpdateSpeed(PAUSED);
} else if (ativityType == DetectedActivity.IN_VEHICLE) {
setUpdateSpeed(FATER);
} else {
setUpdateSpeed(REGULAR);
}
}
}
GoogleCloudMessaging gcm = GoogleCloudMessaging.get(context); gcm.send(to, msgId, data);
<application ...>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="your_api_key" />
</application>
Authentication
Authorization
Google Play Services
startActivityForResult(
AccountPicker.newChooseAccountIntent(null, null
new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE},
true, "Can haz token plz?",
null, null, null) REQUEST_PICK_ACCOUNT);
@Override
protected void onResume() {
super.onResume();
int canIPlay = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
}
mToken = GoogleAuthUtil.getToken(this, "yhwoo.croute@gmail.com", "oauth2:" + Scopes.PLUS_PROFILE + " " + YouTubeScopes.YOUTUBE_READONLY);
Url url = new URL("https://googleapis.com/oauth2/v1/userinfo?access_token=" + token);
...
<com.google.android.gms.plus.PlusOneButton android:id="@+id/plus_button" android:layout_width="match_parent" android:layout_height="wrap_content" plus:annotation="inline" plus:size="standard" />
PlusOneButton button = (PlusOneButton) findViewById(R.id.plus_button); button.initialize(mPlusClient, "http://croute.me", null);
지... 질문 있으신가요?