Dor Mesica
Dor Mesica

Reputation: 527

Getting API key for GCM

I'm trying to register my android app with GCM, I followed the instructions in this link in order to obtain an api key, I did what is written in numbers 1-7 but in step 8 I can't find the Android Key section.

What should I do?

p.s. When I try to register my device with gcm gcm.register(SENDER_ID) I get error saying service not available, are those to problems connected? or this error is something else? (I didn't write the server part of the application)

android manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.appspot.smartgan"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <permission
        android:name="com.appspot.smartgan.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.appspot.smartgan.permission.C2D_MESSAGE" />

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppCompat.Light" >
        <activity
            android:name="com.appspot.smartgan.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <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.appspot.smartgan" />
            </intent-filter>
        </receiver>

        <service android:name=".GcmIntentService" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:name="com.appspot.smartgan.LoginActivity"
            android:label="@string/title_activity_login"
            android:windowSoftInputMode="adjustResize|stateVisible" >
        </activity>
        <activity
            android:name="com.appspot.smartgan.ChildActivity"
            android:label="@string/title_activity_child" >
        </activity>
    </application>

</manifest>

registration code: (I used the code from an example Google published)

private void registerInBackground() {   
    new AsyncTask<Void, Void, String>() {
        String str = "";
        @Override
        protected String doInBackground(Void... params) {
            String message = "";

            try {
                if (gcm == null) {
                    gcm = GoogleCloudMessaging.getInstance(context);
                }
                regid = gcm.register(SENDER_ID);
                message = "Device registered, registration ID=" + regid;

                Log.d("SMARTGAN_PLAY", "register completed");

                // send registration id to the server
                sendRegistrationIdToServer();

                // Persist the regID - no need to register again.
                storeRegistrationId(context, regid);
            } catch (IOException e) {
                message = "Error:" + e.getMessage();
            }
            str = message;
            return message;
        }

        @Override
        protected void onPostExecute(String message) {
            childrenTextView.setText(str);
        }

    }.execute(null, null, null);
}

Upvotes: 1

Views: 1432

Answers (2)

meda
meda

Reputation: 45490

//Subtitute with your own project ID
String SENDER_ID = "46086692976";

See screenshot: enter image description here

Upvotes: 0

Eran
Eran

Reputation: 393771

You don't need an API Key in order to register to GCM. You only need a Sender ID (which is the Project ID of the Google API Project you created for your app). The API Key is only needed in the server side for sending GCM messages to your app.

The reason for getting service not available can be many things. You'll have to post your manifest and client registration code to get more help.

Upvotes: 1

Related Questions