Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android GCM-清单文件和注册_Android_Google Cloud Messaging - Fatal编程技术网

Android GCM-清单文件和注册

Android GCM-清单文件和注册,android,google-cloud-messaging,Android,Google Cloud Messaging,我以前用GCM实施过一个项目。我想现在创建一个新项目,我需要一个新的项目id,我得到了它,但现在我无法注册。是关于项目id的吗?或者我可以使用以前的项目id吗 最后一个问题: <category android:name="my_app_package" /> <permission android:name="my_app_package.permission.C2D_MESSAGE" android:protectionLevel="signature" />

我以前用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页面吗?

首先,如果你想再次注册,你应该取消注册

gcm服务需要应用程序包。 向它注册您的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>



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

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

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


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

首先,您必须遵循GCM的此链接

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

如果您没有从注册中获得响应。主要原因之一是您的清单文件配置不正确…特别是请提供“包名”(您的应用包名,如com.xxx.yyy)正确无误。

您的软件包名称与android:name=“com.ketan.demo.permission.C2D_”消息不匹配。@GooGLE和Vineet Shukla我理解我的软件包名称不同。我写清单文件作为你的,但我仍然得到空的注册id。我还能做什么?然后你必须粘贴代码,这样我才能看到你实际做了什么sogcmregistar.checkDevice(这个);GCMRegistar.检查清单(本);字符串regId=gcmregistar.getRegistrationId(this);if(regId.equals(“”){gcmregistar.register(this,SENDER_ID);}else{MyLog.log(“已注册”);}regId=gcmregistar.getRegistrationId(this);MyLog.log(“寄存器id=“+regId”);System.out.println(“Get Reg ID:+gcmregistar.getRegistrationId(this));当我观看logcat时,我可以看到09-11 13:22:14.708:D/gcmregistar(19154):重置com.example.push的回退09-11 13:22:14.708:V/gcmregistar(19154):在gcmregistar.register注册发送程序668788400385的应用程序com.example.push(这是发送程序的ID);而且注册id总是返回空字符串。谢谢,但我仍然得到空注册id,我无法注册,我还能做什么?gcmregistar.checkDevice(这个);GCMRegistar.检查清单(本);字符串regId=gcmregistar.getRegistrationId(this);if(regId.equals(“”){gcmregistar.register(this,SENDER_ID);}else{MyLog.log(“已注册”);}regId=gcmregistar.getRegistrationId(this);MyLog.log(“寄存器id=“+regId”);System.out.println(“Get Reg ID:+gcmregistar.getRegistrationId(this))@pervin我用同样的代码在另一个项目注册,但现在它不工作了。是关于项目id的吗?我认为我的清单文件也是正确的。当我观看logcat时,我可以看到09-11 13:22:14.708:D/gcmregistar(19154):重置com.example.push的回退09-11 13:22:14.708:V/gcmregistar(19154):在gcmregistar.register注册应用程序com.example.push发件人668788400385(这是发件人的ID);注册id总是返回空字符串。如何声明GCMinentService?检查是否有公共的无参数构造函数。它应该类似于:public gcminentservice(){super(senderID);}
<?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>