2

我之前用 GCM 实现了一个项目。我现在想创建一个新项目,我需要一个新的项目 ID,我得到了它,但现在我无法注册。是关于项目ID的吗?或者我可以使用以前的项目 ID 吗?

最后一个问题:

<category android:name="my_app_package" />   

<permission android:name="my_app_package.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="my_app_package.permission.C2D_MESSAGE" />

什么是应用程序包名称?它在清单文件的顶部吗?还是包含 GCM java 页面?

4

5 回答 5

2
<?xml version="1.0" encoding="utf-8"?>

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

    <!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
    <!-- The targetSdkVersion is optional, but it's always a good practice
         to target higher versions. -->
    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16"/>

    <!-- 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" />

    <!--
     Creates a custom permission so only this app can receive its messages.

     NOTE: the permission *must* be called PACKAGE.permission.C2D_MESSAGE,
           where PACKAGE is the application's package name.
    -->
    <permission
        android:name="com.ketan.demo.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission
        android:name="com.ketan.demo.permission.C2D_MESSAGE" />

    <!-- This app has permission to register and receive data message. -->
    <uses-permission
        android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!-- Main activity. -->
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name="com.ketan.demo.DemoActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <!--
          BroadcastReceiver that will receive intents from GCM
          services and handle them to the custom IntentService.

          The com.google.android.c2dm.permission.SEND permission is necessary
          so only GCM services can send data messages for the app.
        -->
        <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.ketan.demo" />
            </intent-filter>
        </receiver>

        <!--
          Application-specific subclass of GCMBaseIntentService that will
          handle received messages.

          By default, it must be named .GCMIntentService, unless the
          application uses a custom BroadcastReceiver that redefines its name.
        -->
        <service android:name=".GCMIntentService" />
    </application>

</manifest>

我已经实现了 GCM,所以请参考清单文件。

于 2012-09-11T07:21:28.797 回答
0

首先,如果您想再次注册 - 您应该取消注册。

gcm服务需要app包。用它注册你的 GCMBroadcastReceiver。

<receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>

                <!-- Receives the actual messages. -->
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <!-- Receives the registration id. -->
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="my_app_package" />
            </intent-filter>
        </receiver>
于 2012-09-11T07:21:03.783 回答
0

是的,您可以使用以前的 projectID,但是当您发送通知时,使用 projectID 的其他应用程序也可以收到通知,如果您之前注册了它。

您应该能够使用新的项目 ID。也许你做错了什么。再检查一次。

对于您的第二个问题, app_package 是您的应用程序的主包。

于 2012-09-11T07:23:12.280 回答
0

首先,您必须点击 GCM http://developer.android.com/guide/google/gcm/gs.html的此链接

每个项目都有 GCM 的包名称和项目 ID。如果您未指定项目的包名称,则可以使用以前的项目 ID 进行通知。

于 2012-09-11T07:24:41.793 回答
0

如果您没有从注册中得到响应。主要原因之一是您的清单文件配置不正确...尤其是正确地给出“package_name”(您的应用程序包名称,如 com.xxx.yyy)。

于 2013-06-28T22:53:11.477 回答