zoukankan      html  css  js  c++  java
  • AndroidManifest常见的设置解析

      AndroidManifest.xml清单文件是每个Android项目所必需的,它是整个Android项目的全局描述文件。AndroidManifest.xml清单文件说明了该应用的名称、所使用的图标以及包含的组件等。

      AndroidManifest.xml清单文件通常包含如下信息:

      ->应用程序的包名,该包名将会作为该应用的唯一标识。

      ->应用程序所包含的组件,如Activity、Service、BroadcastReceiver和Content Provider等。

      ->应用程序兼容的最低版本。

      ->应用程序使用系统所需的权限声明。

      ->其他程序访问该程序所需的权限声明。

    1)例子1:

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     3         <!--应用程序唯一包名-->
     4     package="com.example.proposalundertake"
     5     <!--应用程序版本号、版本名称-->
     6     android:versionCode="1"
     7     android:versionName="@string/versionName" >
     8 
     9     <uses-sdk
    10         android:minSdkVersion="8"
    11         android:targetSdkVersion="17" />
    12         
    13         <!--声明应用所需要的权限-->
    14     <uses-permission android:name="android.permission.CALL_PHONE" />
    15     <uses-permission android:name="android.permission.INTERNET" />
    16 
    17     <application
    18             <!--应用程序初始化装载的全局Application-->
    19         android:name="com.example.proposalundertake.MyApplication"
    20         android:allowBackup="true"
    21         <!--应用程序图标、应用程序名称、应用程序主题-->
    22         android:icon="@drawable/ic_launcher"
    23         android:label="@string/app_name"
    24         android:theme="@style/AppTheme" >
    25         
    26         <!-- 百度key绑定 -->
    27         <meta-data 
    28             android:name="com.baidu.lbsapi.API_KEY"
    29             android:value="7YHo2b38vOheODLzlpUxRdmn"
    30             />
    31         
    32         <!--service声明-->
    33         <service android:name="com.example.proposalundertake.service.ClientKernelService" android:exported="false">
    34             <intent-filter>
    35                 <action android:name="com.example.proposalundertake.service.ClientKernelService" >
    36                 </action>
    37             </intent-filter>
    38         </service>
    39                
    40         <service android:name="com.example.proposalundertake.bpgmsg.BPGMsgService" android:exported="false">
    41             <intent-filter>
    42                 <action android:name="com.example.proposalundertake.bpgmsg.BPGMsgService" />
    43             </intent-filter>
    44         </service>
    45        
    47         <!-- 欢迎界面0,允许其他程序调用打开该页面-->
    48         <activity
    49             android:name="com.example.proposalundertake.activity.InitActivity"
    50             android:label="@string/app_name"
    51             android:screenOrientation="portrait" 
    52             android:theme = "@style/Transparent"
    53             >   
    54             <intent-filter>
    55                 <action android:name="com.example.proposalundertake.activity.MYACTION" />
    56                 <data android:scheme="info"/>                
    57                 <category android:name="android.intent.category.DEFAULT" />
    58             </intent-filter>
    59         </activity> 
    60               
    63         <!-- 欢迎界面,默认主程序启动页面--> 
    64         <activity
    65             android:name="com.example.proposalundertake.activity.LoginActivity"
    66             android:label="@string/app_name"
    67             android:windowSoftInputMode="stateAlwaysHidden|adjustPan" 
    68             android:screenOrientation="portrait" >
    69             <intent-filter>
    70                 <action android:name="android.intent.action.MAIN" />
    71                 <category android:name="android.intent.category.LAUNCHER" />
    72             </intent-filter>
    73         </activity>         
    74          
    76         <!-- 登录中的更新handler用到的类 -->
    77         <activity
    78             android:name="com.example.proposalundertake.activity.ClientOnTopMessageBox"
    79             android:label="@string/bill_app_name"
    80             android:screenOrientation="portrait"
    81             android:theme="@style/Theme.OnTopDialog"
    82             <!--该页面下软键盘的显示、隐藏形式-->
    83             android:windowSoftInputMode="stateHidden|adjustPan" >
    84         </activity>
    85     </application>
    86 </manifest>

    这里浅谈一下service,其中com.example.proposalundertake.service.ClientKernelService,是自定义继承Service的服务,重写其中的onCreate(),onBind(),

    ,onUnbind(),onDestroy()等(其中,Service的声明周期只继承了onCreate(),onStart(),onDestroy()三个方法)。

    可以通过Intent来启动service:

    1 Intent = new Intent("com.example.proposalundertake.service.ClientKernelService");
    2 Bundle bundle = new Bundle();
    3 bundle.putInt("open",1);
    4 intent.putExtras(bundle);
    5 startService(intent);

    另外,其中com.example.proposalundertake.activity.InitActivity,类别标记为android.intent.category.DEFAULT,也就是可以允许其他程序调用:

     1 // 需要使用Intent类的第2个参数指定Uri
     2 Intent intent = new Intent(
     3         "com.example.proposalundertake.activity.MYACTION",
     4         Uri.parse("info://调用主程序的Activity"));
     5 // 传递6个参数
     6 String ip = LoginActivity.this.getResources().getString(
     7         R.string.heyuan_ip);
     8 String passwordtype = LoginActivity.this.getResources()
     9         .getString(R.string.password_type);
    10 String appname = LoginActivity.this.getResources()
    11         .getString(R.string.app_name);
    12 
    13 intent.putExtra("ip", ip);
    14 intent.putExtra("username", username);
    15 intent.putExtra("password", password);
    16 intent.putExtra("passwordtype", passwordtype); // 服务端加密类型MD5 或 明码等
    17 intent.putExtra("appname", appname); // 主程序应用名称
    18 intent.putExtra("appname_small", appname_small);
    19 startActivity(intent);

    2)例子2:

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     3     package="com.example.proposalbill_hy_lead"
     4     android:versionCode="1"
     5     android:versionName="@string/versionName" >
     6 
     7     <uses-sdk
     8         android:minSdkVersion="16"
     9         android:targetSdkVersion="21" />
    10     
    11     <uses-permission android:name="android.permission.INTERNET"/>
    12     <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
    13     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    14     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    15     
    16     <application
    17         android:allowBackup="true"
    18         android:icon="@drawable/ic_launcher"
    19         android:label="@string/app_name"
    20         android:theme="@style/AppTheme" >
    21         <activity
    22             android:name="com.example.proposalbill_hy_lead.WelcomeActivity"
    23             android:label="@string/app_name" >
    24             <intent-filter>
    25                 <action android:name="android.intent.action.MAIN" />
    26 
    27                 <category android:name="android.intent.category.LAUNCHER" />
    28             </intent-filter>
    29         </activity>
    30         
    31         <activity 
    32             android:name="com.example.proposalbill_hy_lead.LoginActivity"
    33             android:windowSoftInputMode="stateHidden|adjustPan" 
    34             android:screenOrientation="portrait"
    35             ></activity>
    36         
    37         <receiver 
    38             android:name="com.example.proposalbill_hy_lead.TestReceiver2">
    39             <intent-filter>
    40                 <action android:name="com.example.proposalbill.lead"/>
    41             </intent-filter>
    42          </receiver>
    43     </application>
    44 </manifest>

    其中AndroidManifest声明了BroadcastRecevier,com.example.proposalbill_hy_lead.TestReceiver2为继承BroadcastReceiver的类,重写onReceive方法,可以

    处理接收到广播后的动作(如,弹出提示、请求网络数据、结束应用自身等等):

    1 //发送广播,子程序接收广播,结束子程序的登录页面
    2 Intent intent = new Intent();
    3 intent.setAction("com.example.proposalbill.lead");
    4 intent.putExtra("msg", ConstantUtil.appname_small);       //对应要结束的子程序
    5 sendBroadcast(intent);
  • 相关阅读:
    Java对象的生命周期与作用域的讨论(转)
    [置顶] Oracle学习路线与方法
    Java实现 蓝桥杯 算法训练 未名湖边的烦恼
    Java实现 蓝桥杯 算法训练 未名湖边的烦恼
    Java实现 蓝桥杯 算法训练 未名湖边的烦恼
    Java实现 蓝桥杯 算法训练 最大的算式
    Java实现 蓝桥杯 算法训练 最大的算式
    Java实现 蓝桥杯 算法训练 最大的算式
    Java实现 蓝桥杯 算法训练 最大的算式
    Java实现 蓝桥杯 算法训练 最大的算式
  • 原文地址:https://www.cnblogs.com/chq3272991/p/5304957.html
Copyright © 2011-2022 走看看