2012-10-11 80 views
0

我是一位Google云端消息传送的初学者。我正在开发一个演示应用程序来检查GCm的功能。我创建了一个GCM项目,我正在检查设备是否已注册。我使用下面的代码,GCM关闭活动的活动

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     GCMRegistrar.checkDevice(this); 
     GCMRegistrar.checkManifest(this); 
     final String regId = GCMRegistrar.getRegistrationId(this); 
     if (regId.equals("")) { 
      GCMRegistrar.register(this, "483910217912"); 
      Log.d(tag, "Registered"); 
     } else { 
      Log.v(tag, "Already registered"); 
     } 
    } 

和我的清单文件,

<uses-sdk android:minSdkVersion="8" /> 
    <!-- App receives GCM messages. --> 
<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" /> 
<permission android:name="my_app_package.permission.C2D_MESSAGE" android:protectionLevel="signature" /> 
<uses-permission android:name="my_app_package.permission.C2D_MESSAGE" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 
     <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="my_app_package" /> 
    </intent-filter> 
</receiver> 
<service android:name=".GCMIntentService" /> 
     <activity 
      android:name=".GCmExampleActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

我已经包括GSM jar文件到我的项目。

的logcat的错误它给是,

10-11 13:44:59.001: E/AndroidRuntime(339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kochar.it.GCM/com.kochar.it.GCM.GCmExampleActivity}: java.lang.UnsupportedOperationException: Device does not have package com.google.android.gsf 

的错误就行了,

GCMRegistrar.checkDevice(this); 

回答

2

看来你使用了错误的模拟器。默认模拟器使用一个没有任何Google软件包的常规Android模拟器,不能运行各种各样的东西,比如maps,c2dm和类似的东西。你想要做的是创建一个可以支持Google API的新模拟器。

+0

thanx,让我用谷歌API创建一个模拟器。它的工作原理是 –

+0

。我创建了一个支持google api的新模拟器。你能否提出一些关于我应该从哪些项目类型开始的想法。 –

+0

不明白“我应该从哪种类型的项目开始”。 – Deepika

2

不要在模拟器中运行此操作。因为它需要Google帐户。

尝试以下之一,

  1. 与谷歌API来创建仿真 enter image description here
  2. 运行它真正的Android手机
  3. 运行它Bluestack(http://bluestacks.com/

这将解决你的问题。 :)

+0

thanx,让我创建一个模拟器与谷歌API。它的工作原理是 –

+0

。我创建了一个支持google api的新模拟器。 –

+0

欢迎您,不要忘记纠正这个问题。 –