2012-12-14 15 views
2

我想在云中进行登记的设备(谷歌云消息GCM什么是错误在这个GCM代码

但有些错误面向应用

你可以帮我在这

这里是我的清单

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.test09_gsm" 
    android:versionCode="1" 
    android:versionName="1.0" > 

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


    <permission android:name="com.example.test09_gsm.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 

    <uses-permission android:name="com.example.test09_gsme.permission.C2D_MESSAGE" /> 

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


    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.test09_gsm.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="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.test09_gsm" /> 
      </intent-filter> 
     </receiver> 

     <service android:name=".GCMIntentService" /> 
    </application> 


</manifest> 

赫斯在班上是

package com.example.test09_gsm; 

import com.google.android.gcm.GCMBaseIntentService; 
import android.content.Context; 
import android.content.Intent; 
import android.util.Log; 


public class GCMIntentService extends GCMBaseIntentService { 
    public static String TAG = "GCMIntentService"; 

    public GCMIntentService(String senderId) 
    { 
     super(senderId); 
     Log.d("GCMIntentService", senderId); 
    } 

    @Override 
    protected void onError(Context arg0, String arg1) { 
     Log.d("onError", arg1); 
    } 

    @Override 
    protected boolean onRecoverableError(Context context, String errorId){ 
     Log.d("onRecoverableError", errorId); 
     return false; 
    } 

    @Override 
    protected void onMessage(Context arg0, Intent arg1) { 
     Log.d("onMessage", String.valueOf(arg1)); 
    } 

    @Override 
    protected void onRegistered(Context arg0, String arg1) { 
     Log.d("onRegistered", arg1); 
    } 

    @Override 
    protected void onUnregistered(Context arg0, String arg1) { 
     Log.d("onUnregistered", arg1); 
    } 
} 

主要活动

package com.example.test09_gsm; 

import com.google.android.gcm.GCMRegistrar; 

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

public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     GCMRegistrar.checkDevice(this); 
     GCMRegistrar.checkManifest(this); 
     final String regId = GCMRegistrar.getRegistrationId(this); 
     if (regId.equals("")) 
     { 
      GCMRegistrar.register(this, "XXXXXXXXXXXX"); 
     } 
     else 
     { 
      Log.v("Info : ", "Already registered"); 
     } 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) 
    { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 

} 

logcat的

12-15 00:28:28.935: E/Trace(4569): error opening trace file: No such file or directory (2) 
12-15 00:28:29.085: D/GCMRegistrar(4569): resetting backoff for com.example.test09_gsm 
12-15 00:28:29.085: V/GCMRegistrar(4569): Registering app com.example.test09_gsm of senders XXXXXXXXXXXX 
12-15 00:28:29.160: D/libEGL(4569): loaded /system/lib/egl/libEGL_mali.so 
12-15 00:28:29.165: D/libEGL(4569): loaded /system/lib/egl/libGLESv1_CM_mali.so 
12-15 00:28:29.165: D/libEGL(4569): loaded /system/lib/egl/libGLESv2_mali.so 
12-15 00:28:29.170: D/(4569): Device driver API match 
12-15 00:28:29.170: D/(4569): Device driver API version: 10 
12-15 00:28:29.170: D/(4569): User space API version: 10 
12-15 00:28:29.170: D/(4569): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Wed Sep 12 17:53:53 KST 2012 
12-15 00:28:29.205: D/OpenGLRenderer(4569): Enabling debug mode 0 
12-15 00:28:29.985: V/GCMBroadcastReceiver(4569): onReceive: com.google.android.c2dm.intent.REGISTRATION 
12-15 00:28:29.985: V/GCMBroadcastReceiver(4569): GCM IntentService class: com.example.test09_gsm.GCMIntentService 
12-15 00:28:29.985: V/GCMBaseIntentService(4569): Acquiring wakelock 
12-15 00:28:30.000: D/dalvikvm(4569): newInstance failed: no <init>() 
12-15 00:28:30.000: D/AndroidRuntime(4569): Shutting down VM 
12-15 00:28:30.000: W/dalvikvm(4569): threadid=1: thread exiting with uncaught exception (group=0x40e372a0) 
12-15 00:28:30.000: E/AndroidRuntime(4569): FATAL EXCEPTION: main 
12-15 00:28:30.000: E/AndroidRuntime(4569): java.lang.RuntimeException: Unable to instantiate service com.example.test09_gsm.GCMIntentService: java.lang.InstantiationException: can't instantiate class com.example.test09_gsm.GCMIntentService; no empty constructor 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:2388) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at android.app.ActivityThread.access$1600(ActivityThread.java:140) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at android.os.Handler.dispatchMessage(Handler.java:99) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at android.os.Looper.loop(Looper.java:137) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at android.app.ActivityThread.main(ActivityThread.java:4898) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at java.lang.reflect.Method.invokeNative(Native Method) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at java.lang.reflect.Method.invoke(Method.java:511) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at dalvik.system.NativeStart.main(Native Method) 
12-15 00:28:30.000: E/AndroidRuntime(4569): Caused by: java.lang.InstantiationException: can't instantiate class com.example.test09_gsm.GCMIntentService; no empty constructor 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at java.lang.Class.newInstanceImpl(Native Method) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at java.lang.Class.newInstance(Class.java:1319) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  at android.app.ActivityThread.handleCreateService(ActivityThread.java:2385) 
12-15 00:28:30.000: E/AndroidRuntime(4569):  ... 10 more 
现在

我怎么能解决这个问题,并获得注册ID和

+0

我们不能为该文本墙产生响应。请给我们最小的程序 – Woot4Moo

+1

为什么不能? OP添加了相关的代码和logcat。我看着logcat的底部,看到了错误。比我发现有人发布无代码或错误信息的人要好得多 – codeMagic

+0

@ Woot4Moo 我想做类似的事情,我有近10个用户的小型Android应用程序,这个应用程序与sql server数据库相关 我需要当某些用户在数据库中添加/更新/删除某些内容以推送所有其他用户的通知,然后通知(数据库中的某些数据更改)。 – Loai

回答

6

尝试后使用它

在此先感谢将默认构造函数添加到GCMIntentService为:

public GCMIntentService() { 
     super("IntentService"); 
    } 
+0

非常感谢,我怎么知道设备的注册ID是什么? – Loai

+0

@ lo2i:最受欢迎。我不知道这件事。 –

+0

您是否知道我如何通过asp.net将通知推送到设备的其余部分? – Loai