Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 21
Expand All @@ -24,5 +25,5 @@ dependencies {
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.android.support:support-annotations:22.0.0'
compile 'com.google.android.gms:play-services-gcm:7.0.0'
compile 'com.google.android.gms:play-services-gcm:7.5.0'
}
39 changes: 30 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
android:name="android.permission.ACCESS_NETWORK_STATE" />

<!-- Permissions required for Google Cloud Messaging -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.example.android.sunshine.app.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
Expand Down Expand Up @@ -100,15 +101,35 @@
android:resource="@xml/syncadapter" />
</service>

<!-- GCM receiver - Commented out until we write the class -->
<!--<receiver-->
<!--android:name=".GcmBroadcastReceiver"-->
<!--android:permission="com.google.android.c2dm.permission.SEND" >-->
<!--<intent-filter>-->
<!--<action android:name="com.google.android.c2dm.intent.RECEIVE" />-->
<!--<category android:name="com.example.android.sunshine.app" />-->
<!--</intent-filter>-->
<!--</receiver>-->
<!-- The Google Cloud Messaging receiver and services -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.android.sunshine.app" />
</intent-filter>
</receiver>
<service
android:name="gcm.MyGcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<service
android:name="gcm.MyInstanceIDListenerService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
<service
android:name=".gcm.RegistrationIntentService"
android:exported="false" >
</service>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import com.example.android.sunshine.app.sync.SunshineSyncAdapter;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.GoogleApiAvailability;

public class MainActivity extends ActionBarActivity implements ForecastFragment.Callback {

Expand Down Expand Up @@ -67,11 +67,10 @@ protected void onCreate(Bundle savedInstanceState) {
SunshineSyncAdapter.initializeSyncAdapter(this);

if (!checkPlayServices()) {
// this is where we could either prompt a user that they should install
// This is where we could either prompt a user that they should install
// the latest version of Google Play Services, or add an error snackbar
// that some features won't be available.
}

}

@Override
Expand All @@ -93,22 +92,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
startActivity(new Intent(this, SettingsActivity.class));
return true;
}

return super.onOptionsItemSelected(item);
}

@Override
protected void onResume() {
super.onResume();

// If Google Play Services is not available, some features, such as GCM-powered weather
// alerts, will not be available.
if (!checkPlayServices()) {
// Store regID as null
}

String location = Utility.getPreferredLocation(this);
String location = Utility.getPreferredLocation( this );
// update the location in our second pane using the fragment manager
if (location != null && !location.equals(mLocation)) {
if (location != null && !location.equals(mLocation)) {
ForecastFragment ff = (ForecastFragment)getSupportFragmentManager().findFragmentById(R.id.fragment_forecast);
if ( null != ff ) {
ff.onLocationChanged();
Expand Down Expand Up @@ -149,10 +142,11 @@ public void onItemSelected(Uri contentUri) {
* the Google Play Store or enable it in the device's system settings.
*/
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this,
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode,
PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.i(LOG_TAG, "This device is not supported.");
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.google.gms:google-services:1.3.0-beta1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down