2012-07-27 124 views
1

我有几个关于GCM(Google Cloud Messaging)的问题。GCM问题(Google Cloud Messaging)

第一个问题是:我无法启动程序。它似乎总是崩溃:

清单:

<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> 

的代码是:

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; 
    } 
} 

,我收到的是

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 

我有谷歌他们的错误但似乎没有解决办法。

我的第二个问题是: 我如何编写使用GCM 一个PHP的服务器我已经提到: GCM sending with curl (php) GCM with PHP (Google Cloud Messaging)

,我没有得到的东西是什么注册ID意味着

+0

您的清单看起来正确。你有没有尝试卸载应用程序,并重新安装? – azgolfer 2012-07-27 14:45:57

+0

是的,多次。 – user288231 2012-07-27 22:44:44

回答

0

尝试在清单中使用package.GCMIntentService服务

相关问题