1

I have a few questions about GCM (Google Cloud Messaging).

The first question is that: I am unable to start up the program. It seems to be always crashing:

The manifest:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <permission android:name="com.example.gcmtutorial.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcmtutorial.permission.C2D_MESSAGE" /> 
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" /> 
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

          <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" 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.gcmtutorial" />
              </intent-filter>
            </receiver>

        <service android:name=".GCMIntentService" />
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

    </application>

</manifest>

The code is:

package com.example.gcmtutorial;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

import com.google.android.gcm.GCMRegistrar;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        GCMRegistrar.checkDevice(this);
        GCMRegistrar.checkManifest(this);

        final String regId = GCMRegistrar.getRegistrationId(this);
        if (regId.equals("")) {
          GCMRegistrar.register(this, "714669202278");
        } else {
          Log.v("Registered", "Already registered");
        }

        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

The error that I receive is that

07-27 18:11:23.504: E/AndroidRuntime(11390): FATAL EXCEPTION: main
07-27 18:11:23.504: E/AndroidRuntime(11390): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.gcmtutorial/com.example.gcmtutorial.MainActivity}: java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gsf (has extras) } without permission com.google.android.c2dm.permission.RECEIVE
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2205)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.app.ActivityThread.access$600(ActivityThread.java:139)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.os.Looper.loop(Looper.java:156)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.app.ActivityThread.main(ActivityThread.java:4987)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at java.lang.reflect.Method.invokeNative(Native Method)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at java.lang.reflect.Method.invoke(Method.java:511)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at dalvik.system.NativeStart.main(Native Method)
07-27 18:11:23.504: E/AndroidRuntime(11390): Caused by: java.lang.SecurityException: Not allowed to start service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gsf (has extras) } without permission com.google.android.c2dm.permission.RECEIVE
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.app.ContextImpl.startService(ContextImpl.java:1356)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.content.ContextWrapper.startService(ContextWrapper.java:359)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at com.google.android.gcm.GCMRegistrar.internalRegister(GCMRegistrar.java:229)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at com.google.android.gcm.GCMRegistrar.register(GCMRegistrar.java:217)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at com.example.gcmtutorial.MainActivity.onCreate(MainActivity.java:24)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.app.Activity.performCreate(Activity.java:4538)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
07-27 18:11:23.504: E/AndroidRuntime(11390):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
07-27 18:11:23.504: E/AndroidRuntime(11390):    ... 11 more

I have Google them up, but there seems to be no solution.

My second question is: How can I write a php server using GCM I have referred to: GCM sending with curl (php) GCM with PHP (Google Cloud Messaging)

The thing that I don't get is what does registration ID mean

Community
  • 1
  • 1
user288231
  • 995
  • 2
  • 13
  • 24

1 Answers1

0

try package.GCMIntentService in service in your manifest

ess.crazy
  • 296
  • 1
  • 4
  • 24