1 1. 理解 application的图标 和 桌面activity的图标
2 <application
3 //在设置→应用程序→管理应用程序 里面列出的图标
4 android:icon="@drawable/icon5"
5 //在设置→应用程序→管理应用程序 里面列出的名字
6 android:label="@string/app_name"
7 android:theme="@style/AppTheme" >
8 <activity
9 android:name=".ui.SplashActivity"
10 //在手机桌面上生成的图标
11 android:icon="@drawable/icon5"
12 //在手机桌面上生成的名字
13 android:label="@string/app_name" >
14 <intent-filter>
15 <action android:name="android.intent.action.MAIN" />
16
17 <category android:name="android.intent.category.LAUNCHER" />
18 </intent-filter>
19 </activity>
20 </application>
21 在清单文件中对应的节点配置.
22 2. Splash全屏显示
23 // 取消标题栏
24 requestWindowFeature(Window.FEATURE_NO_TITLE);
25 // 完成窗体的全屏显示 // 取消掉状态栏
26 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
27 WindowManager.LayoutParams.FLAG_FULLSCREEN);
28 Ps: 也可以通过主题设置窗体全屏显示
29 android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
30
31 3. pull解析xml
32 /**
33 * 把person.xml的输入流 解析 转化成list集合
34 * @param filename assets目录下的文件名
35 * @return
36 */
37 public List<Person> getPersons(String filename){
38 AssetManager manager = context.getAssets();
39 try {
40 InputStream is = manager.open(filename);
41 //在android下使用pull解析xml文件
42 //1.获取pull解析器的实例
43 XmlPullParser parser = Xml.newPullParser();
44 //2.设置解析器的一些参数
45 parser.setInput(is, "utf-8");
46 // 获取pull解析器对应的事件类型
47 int type = parser.getEventType();
48 Person person = null;
49 List<Person> persons = new ArrayList<Person>();
50 while(type!=XmlPullParser.END_DOCUMENT){
51
52 if(type==XmlPullParser.START_TAG){
53 if("person".equals(parser.getName())){
54 person = new Person();
55 int id =Integer.parseInt( parser.getAttributeValue(0));
56 person.setId(id);
57 }else if("name".equals(parser.getName())){
58 String name = parser.nextText();
59 person.setName(name);
60 }else if("age".equals(parser.getName())){
61 int age = Integer.parseInt( parser.nextText());
62 person.setAge(age);
63 }
64 }
65 if(type==XmlPullParser.END_TAG){
66 if("person".equals(parser.getName())){
67 persons.add(person);
68 person = null;
69 }
70 }
71
72
73 type = parser.next();
74 }
75
76 return persons;
77
78
79 } catch (Exception e) {
80 e.printStackTrace();
81 Toast.makeText(context, "获取person.xml失败", Toast.LENGTH_SHORT).show();
82 return null;
83 }
84 }
85 4. URL httpUrlConnection
86 public UpdateInfo getUpdataInfo(int urlid) throws Exception {
87 String path = context.getResources().getString(urlid);
88 URL url = new URL(path);//将路径解析成url
89 HttpURLConnection conn = (HttpURLConnection) url.openConnection();//打开连接
90 conn.setConnectTimeout(2000);//设置超时时间
91 conn.setRequestMethod("GET");//设置请求方法
92 InputStream is = conn.getInputStream();//获取返回的流
93 //pull解析器解析
94 XmlPullParser parser = Xml.newPullParser();
95 UpdateInfo info = new UpdateInfo();
96 parser.setInput(is, "utf-8");
97 int type = parser.getEventType();
98
99 while (type!=XmlPullParser.END_DOCUMENT) {
100 switch (type) {
101 case XmlPullParser.START_TAG:
102 if ("version".equals(parser.getName())) {
103 info.setVersion(parser.nextText());
104 }else if ("description".equals(parser.getName())) {
105 info.setDescription(parser.nextText());
106 }else if ("apkurl".equals(parser.getName())) {
107 info.setApkurl(parser.nextText());
108 }
109 break;
110
111 }
112 type = parser.next();
113
114 }
115 return info;
116
117 }
118 }
119
120 5. 获取当前客户端版本号
121 PackageInfo info = getPackageManager().getPackageInfo(
122 getPackageName(), 0);
123 return info.versionName;
124
125 6. 安装新的apk
126 激活系统的安装的组件 intent();
127 设置数据 和数据的类型
128 setDataAndType();
129 setData();
130 setType();
131
132 private void install(File file){
133 Intent intent=new Intent();
134 intent.setAction(Intent.ACTION_VIEW);//显示指定数据
135 intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
136 this.finish();
137 startActivity(intent);
138
139 }
140
141 7. 对话框 创建 AlertDialog.buidler
142 Builder.create().show();
143
144 8. Handler message 子线程里面通知主线程ui更新
145 private TextView tv;
146 //1 .创建出来handler 要求必须在主线程里面创建
147 private Handler handler = new Handler(){
148
149 // 主线程处理消息 调用的方法
150 @Override
151 public void handleMessage(Message msg) {
152 int count = (Integer) msg.obj;
153 tv.setText("当前条目为 "+ count);
154 super.handleMessage(msg);
155 }
156
157
158 };
159
160
161
162 @Override
163 public void onCreate(Bundle savedInstanceState) {
164 super.onCreate(savedInstanceState);
165 setContentView(R.layout.main);
166 tv = (TextView) this.findViewById(R.id.tv);
167
168 //每隔2秒钟更新一下 tv的内容
169 new Thread(){
170
171 @Override
172 public void run() {
173 for(int i = 0;i<100;i++){
174 /* tv.setText("当前为"+ i);*/
175 try {
176 sleep(500);
177 } catch (InterruptedException e) {
178 e.printStackTrace();
179 }
180 Message msg = new Message();
181 msg.obj = i;
182 handler.sendMessage(msg);
183
184 }
185 super.run();
186 }
187 }.start();
188
189 }
190
191 9. GridView ListView adapter - > BaseAdapter
192 //将一个XML文件转化成一个view对象
193 View view=View.inflate(context, R.layout.mainscreen_item, null);
194
195 10. Xml ->定义一个背景颜色 shape (参考api文件)
196
197
198 11. Xml -> selector 颜色选择器 根据当前控件的状态显示不同颜色.
199
200 12. Sharedpreference 的使用
201 Sp.edit(); -> Editor editor
202 Editor.put()…
203 Editor.commit(); // 真正的提交数据
204
205 13. 自定义对话框的写法
206 定义一个样式文件 重写了系统的一些默认配置
207 name="android:windowBackground">@drawable/title_background
208 name="android:windowNoTitle">true</item>
209
210 dialog = new Dialog(this, R.style.MyDialog);//R.style.MyDialog 是自定义的一个xml文件
211 dialog.setCancelable(false);
212
213 View view = View.inflate(this, R.layout.normal_entry_dialog, null);
214 et_pwd = (EditText) view.findViewById(R.id.et_normal_entry_pwd);
215 Button bt_normal_ok = (Button) view
216 .findViewById(R.id.bt_normal_dialog_ok);
217 Button bt_normal_cancel = (Button) view
218 .findViewById(R.id.bt_normal_dialog_cancel);
219 bt_normal_ok.setOnClickListener(this);
220 bt_normal_cancel.setOnClickListener(this);
221 dialog.setContentView(view);
222 dialog.show();
223
224
225
226 14. Md5的编码和加密 (不可逆的加密算法)
227
228
229 15. style的使用
230 可以把一些常用的样式定义为style,重复使用。
231 然后style="@style/text_content_style" 直接引用
232
233 16. 更改activity切换的动画效果
234 overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
235
236 17. 获取新打开的activity的返回值
237 StartactivityforResult();
238 SetResultData();
239
240 OnActivityResult();
241
242
243 18. DeviceAdmin的技术 2.2版本支持 -> wipedata() setpwd();
244 不能直接被卸载 在设备管理器里面取消激活 ;
245 主要步骤如下:
246 deviceadmin步骤
247 (1).创建 MyAdmin 的广播接受者 继承 DeviceAdminReceiver
248
249 <receiver android:name=".MyAdmin">
250 <meta-data android:name="android.app.device_admin"
251 android:resource="@xml/my_admin" />
252 <intent-filter>
253 <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
254 </intent-filter>
255 </receiver>
256
257
258 my_admin.xml
259
260 <?xml version="1.0" encoding="utf-8"?>
261 <device-admin xmlns:android="http://schemas.android.com/apk/res/android">
262 <uses-policies>
263 <limit-password />
264 <watch-login />
265 <reset-password />
266 <force-lock />
267 <wipe-data />
268 </uses-policies>
269 </device-admin>
270
271 (2).获取IDevicePolicyManager
272
273
274
275 Method method = Class.forName("android.os.ServiceManager")
276 .getMethod("getService", String.class);
277 IBinder binder = (IBinder) method.invoke(null,
278 new Object[] { Context.DEVICE_POLICY_SERVICE });
279 mService = IDevicePolicyManager.Stub.asInterface(binder);
280
281 (3).注册广播接受者为admin设备
282 ComponentName mAdminName = new ComponentName(this, MyAdmin.class);
283 if (mService != null) {
284 if (!mService.isAdminActive(mAdminName)) {
285 Intent intent = new Intent(
286 DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
287 intent.putExtra (DevicePolicyManager.EXTRA_DEVICE_ADMIN,
288 mAdminName);
289 startActivity(intent);
290 }
291 }
292
293 19 .checkbox的状态 状态变更的监听器
294
295 20 .gps 单态类 , gps wifi 基站
296 获取系统服务LOCATION_SERVICE ->locationManager
297 记得把权限加到清单文件
298
299 21 .广播接受者
300 有序广播 ->1.一般的有序广播 abortbroadcast() (-1000~1000)
301 2.指定了接受者的有序广播setResult();
302
303 无序的广播
304
305 22. 短信内容的处理
306 Object[] pdus = (Object[]) intent.getExtras().get("pdus");
307
308 // 获取短信的内容
309 // #*location*#123456
310 Bundle bundle = intent.getExtras();
311 // 获取接收到的所有短信的信息
312 Object[] pdus = (Object[]) bundle.get("pdus");
313 // 遍历接收到的所有短信的信息
314 for (Object pdu : pdus) {
315 // 获取短信的综合信息
316 SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdu);
317 // 取得短信内容
318 String content = sms.getMessageBody();
319 Log.i(TAG, "短信内容" + content);
320 // 取得短信来源
321 String sender = sms.getOriginatingAddress();