问题:我正在开发内容显示应用程序。现在我想启用 GCM 推送通知应用程序,为此我从
http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/
示例项目工作正常,通知按预期发出。现在我将粘贴的以下文件复制到我的项目中
1. 清单文件
2.xml文件
3. 值文件
4. 主活动文件
我从复制的先前代码中更改了所需的包名称,但它仍然不起作用。请指导我应该更改项目的包名的哪一行,我应该在哪里使用类包名,在哪里我应该使用项目包名。
它给了我错误,因为包名称和子包名称相同。
Code:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<!-- Register Activity -->
<activity
android:name="com.androidhive.pushnotifications.RegisterActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Main Activity -->
<activity
android:name="com.androidhive.pushnotifications.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name" >
</activity>
<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.androidhive.pushnotifications" />
</intent-filter>
</receiver>
<service android:name="com.androidhive.pushnotifications.GCMIntentService" />
</application>
作为 android 开发的新手,我无法弄清楚哪个是此代码中的主要包名称。
任何建议都会很棒!. 提前感谢
我们像这样添加它:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mymain.package"
android:versionCode="1"
android:versionName="1.0" >
Sarthak Mittal是对的,但您还需要更改主要活动的清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mymain.package"
android:versionCode="1"
android:versionName="1.0" >
<activity
android:name="com.androidhive.pushnotifications.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>