美文网首页
Android 笔记整理 - AndroidManifest(应

Android 笔记整理 - AndroidManifest(应

作者: jacob_ | 来源:发表于2019-04-06 15:59 被阅读0次

一、什么是AndroidManifest?

AndroidMainfest是一个应用清单,主要的作用是配置一些App的信息。接下来将一一介绍该应用清单中需要声明的东西。

二、需要声明的东西

2.1.用户权限

<!--用于获取wifi的获取权限,wifi信息会用来进行网络定位-->
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<!--用于访问网络,网络定位需要上网-->
<uses-permission android:name="android.permission.INTERNET"/>

2.2对应用的声明

<application
    android:name=".BaseApp"
    android:allowBackup="true"
    //设置app的图片
    android:icon="@mipmap/ic_launcher"
    //设置app的名称
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    //设置app的名称
    android:theme="@style/AppTheme">

2.2.1 第一行声明了一个application,该BaseApp是该程序运行的时候第一个创建的类

public class BaseApp extends Application {
    private static Context mContext;
    public static long registerOrLogin = 1;
    public static final String APPKEY = "c91b0418d8554d5bc9b32f74";
    /**
     * 维护activity的List
     */
    private static List<Activity> mActivitys = Collections.synchronizedList(new LinkedList<Activity>());
    @Override
    public void onCreate() {
        super.onCreate();
        JMessageClient.init(this,true);
        SharePreferenceManager.init(this,"2DoList_config");
        mContext = this;
        registerActivityListener();
    }

会直接调用Oncreate()

2.3 Activity,service,receiver等必须在AndroidManifest中声明。

        //注意,每个应用清单中必有一个activity具有以下intent-filter,这代表的是该activity是会首先启动的activity,一般设置为开启app首先看见的那个activity。
        <activity android:name=".ui.welcome.WelcomeActivity"
            android:theme="@style/WelcomeStyle">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!--exported代表是否允许其他应用调用该组件-->
        <!--enabled代表该应用是否能够被实例化-->
        <!-- intent-filter表示的是能唤醒该服务的组件-->
        <!-- intent-filter表示的是能唤醒该服务的组件-->
        <service
            android:name="cn.jpush.android.service.PushService"
            android:enabled="true"
            android:exported="false">
            <intent-filter>
                <action android:name="cn.jpush.android.intent.REGISTER" />
                <action android:name="cn.jpush.android.intent.REPORT" />
                <action android:name="cn.jpush.android.intent.PushService" />
                <action android:name="cn.jpush.android.intent.PUSH_TIME" />
            </intent-filter>
        </service>
        <!-- android:process=":remote"的意思是让该接收机运行在远端进程而不是当前apk的进程中-->
        <receiver android:name=".service.AlarmReceiver"
            android:process=":remote">
            <intent-filter >
                <action android:name="com.android.deskclock.ALARM_ALERT"/>
            </intent-filter>
        </receiver>
        <!-- 定义在application内,但在activity之外-->
        <meta-data
            android:name="JPUSH_CHANNEL"
            android:value="developer-default" />

        <!-- Required. AppKey copied from Portal -->
        <meta-data
            android:name="JPUSH_APPKEY"
            android:value="***" />
    </application>

通过使用<meta-data>,开发人员可以与使用者共享第三方库或APIs的KEY

相关文章

网友评论

      本文标题:Android 笔记整理 - AndroidManifest(应

      本文链接:https://www.haomeiwen.com/subject/yqmriqtx.html