28

如何在我的 android 清单中注册我的应用程序类?我在网上看了很多教程,仍然不能正确。我的应用程序类称为Monitor.java. 如何在下面的 Manifest 文件代码中注册它?

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

<application
    android:allowBackup="true"
    android:debuggable="true"
    android:icon="@drawable/ic_launcher"
    android:label="xyz"
    android:screenOrientation="landscape"
    android:theme="@style/AppTheme" >

    <service
        android:name=".AudioService"
        android:icon="@drawable/ic_launcher"
        android:label="audioservice" >
    </service>

    <activity
        android:name=".MainActivity"
        android:screenOrientation="landscape" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <activity
        android:name=".Editor"
        android:screenOrientation="landscape"
        android:windowSoftInputMode="stateHidden" >
        <intent-filter>
            <action android:name="com.example.project.EDITOR" />

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

</application>

4

7 回答 7

58
<application
        android:name="package.YourApplicationClass"  <--------
        android:allowBackup="true"
        android:debuggable="true"
        android:icon="@drawable/ic_launcher"
        android:label="xyz"
        android:screenOrientation="landscape"
        android:theme="@style/AppTheme">
于 2012-12-19T09:58:48.757 回答
7

尝试这个:

 <application android:icon="@drawable/icon" 
       android:label="@string/app_name" 
       android:name="Monitor">

请参阅下面的良好参考链接:

如何使用Android的Application对象

谢谢。

于 2012-12-19T09:58:01.403 回答
3

简单,将android:name您的应用程序类名称的属性放在应用程序的Manifest.xml<application />的标记中

<application
 android:name=".Monitor"
   .... >

更新:

应用类:

需要维护全局应用程序状态的基类。您可以通过在 AndroidManifest.xml 的标签中指定其名称来提供自己的实现,这将导致在创建应用程序/包的进程时为您实例化该类。

更多信息请查看http://developer.android.com/reference/android/app/Application.html

于 2012-12-19T09:57:26.363 回答
1

好吧,你里面已经有了应用程序类——从<application. 如果您Application的代码中有一个自定义类(扩展)并希望它启动 - 放置

android:name=".Monitor" (or full path like com.something.app.Monitor)

<application标签之后(与添加活动相同的过程)。

于 2012-12-19T09:57:02.120 回答
1

只需android:name=".Monitor"在标签中添加一个属性application(我假设 Monitor.java 类位于应用程序包的根目录中)。希望这可以帮助。

于 2012-12-19T09:58:31.613 回答
1

让我感到困惑的是 'android:name' 在清单文件中多次出现。在创建应用程序类文件之前,我有

android:name=".MainActivity"

在“活动”标签之后。

创建应用程序文件后,清单文件中的所有内容都保持不变,除了在“应用程序”标签之后,我添加

android:name=".myApplicationClass"

我完整的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="pixtas.com.nightout" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!--
      IMPORTANT: Change "com.parse.tutorials.pushnotifications.permission.C2D_MESSAGE" in the lines below
      to match your app's package name + ".permission.C2D_MESSAGE".
    -->
    <permission android:protectionLevel="signature"
        android:name="pixtas.com.nightout.permission.C2D_MESSAGE" />
    <uses-permission android:name="pixtas.com.nightout.permission.C2D_MESSAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:name=".myApplicationClass" >


        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <service android:name="com.parse.PushService" />
        <receiver android:name="com.parse.ParseBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.parse.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" />

                <!--
                  IMPORTANT: Change "com.parse.tutorials.pushnotifications" to match your app's package name.
                -->
                <category android:name="pixtas.com.nightout" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false">
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>

        <!-- replace @drawable/push_icon with your push icon identifier -->
        <meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/ic_launcher"/>

    </application>

</manifest>
于 2015-03-21T02:31:51.640 回答
0

用这个

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testing"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="16" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Monitor"
        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>

</manifest>
于 2012-12-19T10:00:30.830 回答