Using GCM in android studio

I do not know how to get GCM to work in my project in Android studio.

When I use some GCM clans, you will get this: Cannot resolve the symbol GCMRegistrar In this code:

GCMRegistrar.checkDevice(this); 

And it does not show the ability to import a class.

This is my graddle file:

  buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.8.0' } } apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 19 buildToolsVersion "19.0.1" defaultConfig { minSdkVersion 9 targetSdkVersion 19 } } dependencies { compile 'com.android.support:appcompat-v7:19.0.1' compile 'com.google.android.gms:play-services:4.2.42' } 

This is my manifest:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.compage.womenshield" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.READ_PROFILE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" /> <uses-permission android:name="android.permission.SEND_SMS" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.VIBRATE" /> <permission android:name="com.compage.womenshield.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.compage.womenshield.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-feature android:glEsVersion="0x00020000" android:required="true"/> <application android:allowBackup="true" android:icon="@drawable/icono_app" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.compage.womenshield.Splash" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyCgQNclD9ZqxhiJXGdFvTTx2OiR_vKfJCM"/> <receiver android:name=".GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <!-- Receives the actual messages. --> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <!-- Receives the registration id. --> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.javapapers.android" /> </intent-filter> </receiver> <service android:name="com.compage.womenshield.notification.GCMIntentService" /> </application> </manifest> 

The error is displayed here:

 <receiver android:name=".GCMBroadcastReceiver" 

In the name of the class. And here:

 <service android:name="com.compage.womenshield.notification.GCMIntentService" /> 

How can I use these gcm classes in android studio?

+7
android android-studio push-notification google-cloud-messaging
source share
2 answers

You are probably using an old tutorial, but GCMRegistrar is an obsolete API class.

You really have to use the new one as it will be removed soon.

Use GoogleCloudMessaging instead .

+4
source share

You are using the older method. you have to check n google doc to use gcm in your app. now to get the token the instance id is used

 String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); 

for the full tutorial you can check the tutorial

0
source share

All Articles