点开头像,是一个gridview,里面编写你所需要的图片地址,获取到图片信息,显示出来,写一个bean,set一个图片的String加载到bean,点击图片后将imageview,再getbean就行了
天镇ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!
可以用popupwindow,dialog是达不到效果的
dialog会覆盖到整个屏幕上面的,要么就修改dialog的theme。
这个属于调用系统相册和系统相机进行图片选择的问题
客服端代码:
[java] view plaincopyprint?
01.package com.cn.lxz.zhaopian;
02.
03.import java.io.File;
04.import java.io.IOException;
05.import java.text.SimpleDateFormat;
06.import java.util.Date;
07.import java.util.HashMap;
08.import java.util.Map;
09.
10.import lxz.utils.android.graphics.GraphicsBitmapUtils;
11.import lxz.utils.android.net.UploadFile;
12.import lxz.utils.android.resource.AndroidClass;
13.
14.import android.app.Activity;
15.import android.app.AlertDialog;
16.import android.content.DialogInterface;
17.import android.content.DialogInterface.OnClickListener;
18.import android.content.Intent;
19.import android.content.res.Resources;
20.import android.graphics.Bitmap;
21.import android.graphics.drawable.BitmapDrawable;
22.import android.graphics.drawable.Drawable;
23.import android.net.Uri;
24.import android.os.Bundle;
25.import android.os.Environment;
26.import android.os.Handler;
27.import android.os.Message;
28.import android.provider.MediaStore;
29.import android.view.View;
30.import android.widget.Button;
31.import android.widget.EditText;
32.import android.widget.ImageView;
33.import android.widget.Toast;
34.
35.public class Activity_UploadPic extends Activity implements Handler.Callback {
36. /** Called when the activity is first created. */
37.
38. ImageView view_pic;
39. Button view_btn;
40. EditText view_et;
41. // 线程通知上传成功
42. final Handler upLoadhand = new Handler(this);
43. String[] arrayString = { "拍照", "相册" };
44. String title = "上传照片";
45.
46. // 上传的地址
47. String uploadUrl = "?";
48. String filename = "照片";
49. private static final int PHOTO_REQUEST_TAKEPHOTO = 1;// 拍照
50. private static final int PHOTO_REQUEST_GALLERY = 2;// 从相册中选择
51. private static final int PHOTO_REQUEST_CUT = 3;// 结果
52.
53. @Override
54. public boolean handleMessage(Message msg) {
55.
56. if (msg.obj != null) {
57. Drawable drawable = new BitmapDrawable((Bitmap) msg.obj);
58. view_pic.setBackgroundDrawable(drawable);
59. Toast.makeText(this, "获得图片并且头像上传成功", 3).show();
60. }else
61. {
62. Toast.makeText(this, "获得图片,但是头像上传失败,请注意配置uploadUrl上传地址", 3).show();
63. }
64.
65. return false;
66. }
67.
68. // 创建一个以当前时间为名称的文件
69. File tempFile = new File(Environment.getExternalStorageDirectory(),
70. getPhotoFileName());
71.
72. // 对话框
73. OnClickListener onDialogClick = new OnClickListener() {
74. @Override
75. public void onClick(DialogInterface dialog, int which) {
76. switch (which) {
77. case 0:
78. startCamearPicCut(dialog);// 开启照相
79. break;
80. case 1:
81. startImageCaptrue(dialog);// 开启图库
82. break;
83. default:
84. break;
85. }
86. }
87.
88. private void startCamearPicCut(DialogInterface dialog) {
89. // TODO Auto-generated method stub
90. dialog.dismiss();
91. // 调用系统的拍照功能
92. Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
93.
94. intent.putExtra("camerasensortype", 2);// 调用前置摄像头
95. intent.putExtra("autofocus", true);// 自动对焦
96. intent.putExtra("fullScreen", false);// 全屏
97. intent.putExtra("showActionIcons", false);
98. // 指定调用相机拍照后照片的储存路径
99. intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
100. startActivityForResult(intent, PHOTO_REQUEST_TAKEPHOTO);
101. }
102.
103. private void startImageCaptrue(DialogInterface dialog) {
104. // TODO Auto-generated method stub
105. dialog.dismiss();
106. Intent intent = new Intent(Intent.ACTION_PICK, null);
107. intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
108. "image/*");
109. startActivityForResult(intent, PHOTO_REQUEST_GALLERY);
110. }
111. };
112.
113. @Override
114. public void onCreate(Bundle savedInstanceState) {
115. super.onCreate(savedInstanceState);
116. setContentView(R.layout.main);
117. init();
118.
119. }
120.
121. private void init() {
122. // TODO Auto-generated method stub
123. view_pic = (ImageView) findViewById(R.id.iv);
124. view_btn = (Button) findViewById(R.id.btn);
125. view_et = (EditText) findViewById(R.id.et);
126. view_btn.setOnClickListener(new View.OnClickListener() {
127.
128. @Override
129. public void onClick(View v) {
130. // TODO Auto-generated method stub
131. AlertDialog.Builder dialog = AndroidClass.getListDialogBuilder(
132. Activity_UploadPic.this, arrayString, title,
133. onDialogClick);
134. dialog.show();
135. }
136. });
137. }
138.
139. // 使用系统当前日期加以调整作为照片的名称
140. private String getPhotoFileName() {
141. Date date = new Date(System.currentTimeMillis());
142. SimpleDateFormat dateFormat = new SimpleDateFormat(
143. "'IMG'_yyyyMMdd_HHmmss");
144. return dateFormat.format(date) + ".jpg";
145. }
146.
147. @Override
148. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
149. super.onActivityResult(requestCode, resultCode, data);
150. switch (requestCode) {
151. case PHOTO_REQUEST_TAKEPHOTO:
152. startPhotoZoom(Uri.fromFile(tempFile), 150);
153. break;
154.
155. case PHOTO_REQUEST_GALLERY:
156. if (data != null) {
157. startPhotoZoom(data.getData(), 150);
158. }
159. break;
160.
161. case PHOTO_REQUEST_CUT:
162. if (data != null) {
163. setPicToView(data);
164. }
165. break;
166. }
167. super.onActivityResult(requestCode, resultCode, data);
168. }
169.
170. private void startPhotoZoom(Uri uri, int size) {
171. Intent intent = new Intent("com.android.camera.action.CROP");
172. intent.setDataAndType(uri, "image/*");
173. // crop为true是设置在开启的intent中设置显示的view可以剪裁
174. intent.putExtra("crop", "true");
175.
176. // aspectX aspectY 是宽高的比例
177. intent.putExtra("aspectX", 1);
178. intent.putExtra("aspectY", 1);
179.
180. // outputX,outputY 是剪裁图片的宽高
181. intent.putExtra("outputX", size);
182. intent.putExtra("outputY", size);
183. intent.putExtra("return-data", true);
184.
185. startActivityForResult(intent, PHOTO_REQUEST_CUT);
186. }
187.
188. // 将进行剪裁后的图片显示到UI界面上
189. private void setPicToView(Intent picdata) {
190. Bundle bundle = picdata.getExtras();
191. if (bundle != null) {
192. final Bitmap photo = bundle.getParcelable("data");
193.
194. new Thread() {
195.
196. @Override
197. public void run() {
198. byte[] photodata = GraphicsBitmapUtils.Bitmap2Bytes(photo);
199. UploadFile uploadFile = new UploadFile(uploadUrl);
200. Map parameters = new HashMap();
201. parameters.put("msg", view_et.getText().toString());
202.
203. boolean isUploadSuccess = false;
204.
205. try {
206. isUploadSuccess = uploadFile.defaultUploadMethod(
207. photodata, filename, parameters);
208. } catch (IOException e) {
209. // TODO Auto-generated catch block
210. e.printStackTrace();
211. }
212.
213. if (isUploadSuccess) {
214. upLoadhand.obtainMessage(0, photo).sendToTarget();
215. } else {
216. upLoadhand.obtainMessage(-1, null).sendToTarget();
217. }
218.
219. }
220. }.start();
221.
222. }
223. }
224.
225.}
监听消息,得到数目,在app图标上画出数字(canvas),然后替换桌面快捷方式
public void createShortCut(){
//创建快捷方式的Intent
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
//不允许重复创建
shortcutintent.putExtra("duplicate", false);
//需要现实的名称
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
//快捷图片(每次重绘logo生成一张新图)
Parcelable icon = Intent.ShortcutIconResource.fromContext(activity, R.drawable.logo);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
//点击快捷图片,运行的程序主入口
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent());
//发送广播。OK
sendBroadcast(shortcutintent);
}
}
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款