【问题标题】:Title: How to differentiate sub package and main package name in android?标题:android中如何区分子包和主包名?
【发布时间】:2015-01-23 15:05:21
【问题描述】:

问题:我正在开发内容展示应用。现在我想启用 GCM 推送通知应用程序,为此我从

下载了一个示例项目

http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

示例项目运行良好,通知按预期发送。 现在我将以下文件复制粘贴到我的项目中
1.清单文件
2.xml文件
3. 值文件
4. MainActivity 文件

我从之前复制的代码中更改了我需要的 Packagename,但它仍然无法正常工作。请指导我应该在哪一行更改项目的包名,我应该在哪里使用类包名以及我应该在哪里使用项目包名。

因为包名和子包名相同,所以报错。

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 开发的新手,我无法弄清楚这段代码中的主包名称。

任何建议都会很棒!提前致谢

【问题讨论】:

  • 您收到的确切错误是什么,您在哪里看到的?

标签: java android import package android-debug


【解决方案1】:

我们这样添加:

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

【讨论】:

    【解决方案2】:

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-09
      • 2017-02-25
      • 2023-02-03
      相关资源
      最近更新 更多