GCM活动被强制关闭

时间:2012-10-11 08:47:14

标签: android error-handling google-cloud-messaging

我是Google云消息传递的初学者。我正在开发一个演示应用程序来检查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 个答案:

答案 0 :(得分:2)

您似乎使用了错误的模拟器。默认模拟器使用的是常规Android模拟器,它没有任何Google软件包,也无法运行各种各样的东西,比如map,c2dm和各种各样的东西。您想要做的是创建一个可以支持Google API的新模拟器。

答案 1 :(得分:2)

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

尝试下面的一个,

  1. 使用Google API创建模拟器 enter image description here
  2. 在真正的Android手机上运行它
  3. 在Bluestack(http://bluestacks.com/
  4. 上运行它

    它将解决您的问题。 :)

相关问题