2011年5月 的存档
2011五月28

Android:指定分辨率和清晰度的图片压缩方法源码

public void transImage(String fromFile, String toFile, int width, int height, int quality)
	{
		try
		{
			Bitmap bitmap = BitmapFactory.decodeFile(fromFile);
			int bitmapWidth = bitmap.getWidth();
			int bitmapHeight = bitmap.getHeight();
			// 缩放图片的尺寸
			float scaleWidth = (float) width / bitmapWidth;
			float scaleHeight = (float) height / bitmapHeight; 
			Matrix matrix = new Matrix();
			matrix.postScale(scaleWidth, scaleHeight);
			// 产生缩放后的Bitmap对象
			Bitmap resizeBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmapWidth, bitmapHeight, matrix, false);
			// save file
			File myCaptureFile = new File(toFile);
			FileOutputStream out = new FileOutputStream(myCaptureFile);
			if(resizeBitmap.compress(Bitmap.CompressFormat.JPEG, quality, out)){
				out.flush();
				out.close();
			}
			if(!bitmap.isRecycled()){
				bitmap.recycle();//记得释放资源,否则会内存溢出
			}
			if(!resizeBitmap.isRecycled()){
				resizeBitmap.recycle();
			}

		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException ex)
		{
			ex.printStackTrace();
		}
	}
2011五月27

请姑娘吃冰淇淋

最近哥们天天请一姑娘吃冰淇淋,不解,问起原因,答曰:科学表明女生经期的时候表白成功几率大,又不好意思问姑娘的日子,就天天请冰淇淋,等哪天姑娘不吃了肯定就是来了没跑儿……(转)

2011五月26

eclipse 3.6.2中文汉化包

下载地址:http://u.115.com/file/clctrq2u

使用方法:解压缩后,覆盖到eclipse相应目录下,重新运行即可。

2011五月25

某男网上征婚

某男网上征婚,开出条件:要美,能做饭。电脑搜索后结果显示:美的电饭煲。不甘心,再搜:要高,要修长。结果显示:旗杆。又再搜:要前凸后翘。结果显示:芙蓉姐姐。仍然不满意,将上述条件全部输入,结果相当惊人,达到择偶至高标准: “芙蓉姐姐背着一个美的电饭煲爬旗杆。

2011五月25

安徽电信 CDMA iPhone 4 烧号写号最新进展,3G完美解决(附代理经销商名单)

2011/5/26

安徽省电信CMDA iPhone 4 经销商名单:

2011/4/26

博主终于完美3G了,现在安徽CDMA iPhone 4 电话、短信、3G上网都OK,彩信和facetime暂时不行,不过后两者可有可无哈哈。

看看3G看优酷视频的速度,……

OMG网速这么快,流量不够用啊不够用啊。。。下个月开800M+100M流量~~~

PS:@安徽天翼苹果看到很多喷油在微博里留言和咨询CDMA IPHONE4的相关问题,介个请大家放心,据我得到的可靠消息,政策马上就会出来,两周之内应该没神马问题。请大家耐心等待一下,有最新进展我会第一时间在微博里通知大家。

2011/4/21

@安徽天翼苹果:劲暴消息,安徽CDMA版IPHONE写号具体政策出台!针对新用户入网,4500元购机,送3000元话费。话费返还方式为:次月返还上月话费的40%,两年内消费完。如果用户有老号码也可直接写号,同样4500元购机,但老用户需在号码上面加装一个至少20元价值的上网流量包。

2011/4/20

@安徽天翼苹果:据刚刚得到的确切小道消息,安徽近日将对全省开放天翼IPHONE4写号,并给每个购机用户配以3000元巨额话费 !安徽的果粉们有福啦,有福啦!想要疯4的人啊,有木有,有木有!!

2011/4/13

安徽电信已开放3G功能。
博主RP大爆发,是安徽电信唯一一个3G没开放成功的,可能与我1X挂QQ有关,惨。
只能等明天再试了。。。

2011/4/12

阿郎区已经取得重大突破。。安徽全省可烧号。
哇哈哈,站长 CDMA iPhone 4 写号成功,可以打电话发短信和WAP上网,3G要过2天统一开放。
安徽前十个用上的用户哦~~~

注:我不是电信的,不能帮忙烧号。
手机之所以能烧号是因为拿去帮忙测试,请留意安徽天翼苹果最新动态,离开放不远了。:)

 

2011/4/9

芜湖拨号写合肥号码测试进行中。。(看来阿郎区短时间么希望)

2011/4/8

昨天对OTA平台进行了升级,现在能把电话、短信、3G一把全部实现,当然3G需要后端配合。

2011/4/5

阿郎区烧号测试或B计划正在进行中,进展不详。
不过从新浪微博上窥探的消息来看,安徽电信内部员工还有一些V字认证的,
已经开始入手CDMA iPhone 4,并有消息称本周内部分开放烧号(猜测)。

关注动态:安徽天翼苹果

2011/4/1

阿郎区第二次烧号测试失败,阿郎真的很弱。。等待B计划实施。

2011/3/30

昨天阿郎设备升级,今天进行阿郎区第二次烧号测试。等待结果。

2011/3/29

新浪微博 @安徽天翼苹果 连发数篇文章:

此图说明神马捏? 有图有真相!你懂的。。。关键内容在左上角哦!

根据电信人士微博中透露的情况,果粉们在购买C网IPHONE的时候应该优先选择未激活版本,这样在写号时相对简单。那么什么是未激活版本呢?小编在这里稍作解释:未激活版本就是未被Verizon写号的机器,这种机器开机以后会提示正在等待激活(见下图),无法检测到运营商的信号。赶快买吧,估计要涨价啦!

PS:据可靠消息,目前安徽电信CDMA iPhone 4烧号,已可短信、电话、3G上网,

唯一的缺憾是要到芜湖烧号(江南地区是中兴基站),江北地区阿朗区暂时还不能烧号,

江北地区(包括合肥)的烧号技术问题还在积极解决中。

不过对于果粉来说,跑芜湖一趟烧个号,也是可以接受的哈。。。总比当砖强。 

2011/3/28

可以3G了。。

2011/3/26

阿郎区烧号测试失败。:(

2011/3/24

最新消息,明天安徽电信将进行江北区CDMA iPhone 4 烧号测试,测试通过则全省可烧号。

2011/3/22

@安徽天翼苹果:据传,安徽已成功完成第一部IPHONE4写号工作,目前已经能够正常拨打电话、收发短信和3G上网。目前尚未有相关图片登出,我们将密切关注事态进展。

目前安徽江南城市已可正常烧号,江北城市还在进行工作。最郁闷的是,合肥是属于江北城市。

还要等待,不过相信好消息会接踵而来。。

2011/3/19

阿郎设备不支持OTA,正在调试中兴设备。。

2011/3/14

刚开始进行ota搭建……  表示进度有些慢。。

evdo还是解决不掉。。另外开放不开放面临很大风险,现在还是未知。

PS:广东解决evdo(不完美)了。是否意味着安徽电信也有希望?

2011/3/11

据说目前可以烧号的省份,只能拨打电话和短信,

3G上网没攻破。:( 另说华为那边3G有进展。。

后续:晚间老总说下周即可小范围烧号,虽说3G也可以,但可能因为监管问题也不能成行。

2011/3/10

目前安徽这边架设ota物理资源和方案都已经好了,

但是涉及到现网改造,部门经理做不了主,要跟领导汇报。

2011/3/9

硬件已经基本到位,领导在协调资源,物理资源、逻辑资源。

2011/3/7

正在和厂家商量怎么建设ota的实验网,方案已经出来了,现在只等领导批准,

本省没有ota设备,所以需要现搭,估计最迟下周就可以烧好。

因为涉及到购买新设备,所以会花点时间,开放不开放烧号得领导决策。

2011五月19

Android:解决ProgressDialog提示框不转动

ProgressDialog 解决“第一次执行图标转动,第二次执行不转动”代码:

@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case PROGRESS_DIALOG:
			progressDialog = new ProgressDialog(LoginActivity.this);
			progressDialog.setMessage("正在登陆,请稍等...");
			progressDialog.setCancelable(true);
			// 设置ProgressDialog 是否可以按退回按键取消
			return progressDialog;
		default:
			return null;
		}
	}

	@Override
	protected void onPrepareDialog(int id, Dialog dialog) {
		switch (id) {
		case PROGRESS_DIALOG:
			dialog
					.setOnDismissListener(new DialogInterface.OnDismissListener() {
						@Override
						public void onDismiss(DialogInterface dialog) {
							removeDialog(PROGRESS_DIALOG);//这个起作用
							if (progressThread != null) {
								progressThread = null;
							}
						}
					});
		}
	}
2011五月19

Android:设置APN为cmnet源码

public class APNActivity extends Activity {

        public static final Uri APN_URI = Uri.parse("content://telephony/carriers");
        public static final Uri CURRENT_APN_URI = Uri.parse("content://telephony/carriers/preferapn");

        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                int _cmnetId = addAPN();
                SetAPN(_cmnetId);
        }
       public void checkAPN(){
      // 检查当前连接的APN
              Cursor cr = getContentResolver().query(CURRENT_APN_URI, null, null,
              null, null);
              while (cr != null && cr.moveToNext()) {
                  // APN id
                  String id = cr.getString(cr.getColumnIndex("_id"));
                  // APN name
                  String apn = StringUtils.null2String(cr
                  .getString(cr.getColumnIndex("apn")));
                  // Toast.makeText(getApplicationContext(),
                  // "当前 id:" + id + " apn:" + apn, Toast.LENGTH_LONG).show();

       }

        //新增一个cmnet接入点
        public int addAPN() {
                int id = -1;
                ContentResolver resolver = this.getContentResolver();
                ContentValues values = new ContentValues();
                values.put("name", "cmnet");
                values.put("apn", "cmnet");
                Cursor c = null;
                Uri newRow = resolver.insert(APN_URI, values);
                if (newRow != null) {
                        c = resolver.query(newRow, null, null, null, null);
                        int idIndex = c.getColumnIndex("_id");
                        c.moveToFirst();
                        id = c.getShort(idIndex);
                }
                if (c != null)
                        c.close();
                return id;
        }
        //设置接入点
        public void SetAPN(int id) {
                ContentResolver resolver = this.getContentResolver();
                ContentValues values = new ContentValues();
                values.put("apn_id", id);
                resolver.update(CURRENT_APN_URI, values, null, null);
        }
}
2011五月19

中央台

中央台一套:我们幸福,你们羡慕;二套:我们爱讲冷笑话;三套:看载歌载舞,想民生民主;四套:日韩折腾,港澳顺从;中央五套:大球看世界,小球看中国;中央六套:电影免费看,每天都抗战;中央七套:部队威武,农民不苦;八套:国产无好片,只播新泰韩;戏曲频道:你必须听京剧,因为你已别无选择。@情流感

2011五月18

和交往4年的女朋友分手了

和交往4年的女朋友分手了。昏天黑地地上了双层大巴。旁边坐个美女也提不起兴趣打量!售票员过来卖票,我以为是空调车就递过去两块,售票员看了我们两个一眼就撕给我两张一块钱的票。我楞了一下,懒得解释,继续头靠窗户回忆我四年的感情,不知不觉泪流满面!美女突然说话了:就一块钱,至于吗?

2011五月18

Android:实用代码(开启启动、建立GPRS连接、闹钟等)

1:查看是否有存储卡插入

String status=Environment.getExternalStorageState();
if(status.equals(Enviroment.MEDIA_MOUNTED))
{
说明有SD卡插入
}

2:让某个Activity透明

OnCreate中不设Layout
this.setTheme(R.style.Theme_Transparent);

以下是Theme_Transparent的定义(注意transparent_bg是一副透明的图片)

3:在屏幕元素中设置句柄

使用Activity.findViewById来取得屏幕上的元素的句柄. 使用该句柄您可以设置或获取任何该对象外露的值.
TextView msgTextView = (TextView)findViewById(R.id.msg);
msgTextView.setText(R.string.push_me);

4:发送短信

String body=”this is mms demo”;

Intent mmsintent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(”smsto”, number, null));
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, true);
mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, true);
startActivity(mmsintent);

5:发送彩信

StringBuilder sb = new StringBuilder();

sb.append(”file://”);

sb.append(fd.getAbsoluteFile());

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(”mmsto”, number, null));
// Below extra datas are all optional.
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT, subject);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY, body);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_CONTENT_URI, sb.toString());
intent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE, composeMode);
intent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT, exitOnSent);

startActivity(intent);

6:发送Mail

mime = “img/jpg”;
shareIntent.setDataAndType(Uri.fromFile(fd), mime);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fd));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

shareIntent.putExtra(Intent.EXTRA_TEXT, body);

7:注册一个BroadcastReceiver

registerReceiver(mMasterResetReciever, new IntentFilter(”OMS.action.MASTERRESET”));

private BroadcastReceiver mMasterResetReciever = new BroadcastReceiver() {

public void onReceive(Context context, Intent intent){
String action = intent.getAction();
if(”oms.action.MASTERRESET”.equals(action)){
RecoverDefaultConfig();
}
}

};

8:定义ContentObserver,监听某个数据表

private ContentObserver mDownloadsObserver = new DownloadsChangeObserver(Downloads.CONTENT_URI);

private class DownloadsChangeObserver extends ContentObserver {
public DownloadsChangeObserver(Uri uri) {
super(new Handler());

}

@Override
public void onChange(boolean selfChange) {}
}

9:获得 手机UA

public String getUserAgent()
{
String user_agent = ProductProperties.get(ProductProperties.USER_AGENT_KEY, null);
return user_agent;
}

10:清空手机上Cookie

CookieSyncManager.createInstance(getApplicationContext());
CookieManager.getInstance().removeAllCookie();

11:建立GPRS连接

//Dial the GPRS link.
private boolean openDataConnection() {
// Set up data connection.
DataConnection conn = DataConnection.getInstance();

if (connectMode == 0) {
ret = conn.openConnection(mContext, “cmwap”, “cmwap”, “cmwap”);
} else {
ret = conn.openConnection(mContext, “cmnet”, “”, “”);
}

}

12:PreferenceActivity 用法

public class Setting extends PreferenceActivity

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.settings);
}

Setting.xml:

Android:key=”seting2″
android:title=”@string/seting2″
android:summary=”@string/seting2″/>

android:key=”seting1″
android:title=”@string/seting1″
android:summaryOff=”@string/seting1summaryOff”
android:summaryOn=”@stringseting1summaryOff”/>

13:通过HttpClient从指定server获取数据

DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet method = new HttpGet(“http://www.baidu.com/1.html”);
HttpResponse resp;
Reader reader = null;
try {
// AllClientPNames.TIMEOUT
HttpParams params = new BasicHttpParams();
params.setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, 10000);
httpClient.setParams(params);
resp = httpClient.execute(method);
int status = resp.getStatusLine().getStatusCode();

if (status != HttpStatus.SC_OK) return false;

// HttpStatus.SC_OK;
return true;
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (reader != null) try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

14:显示toast

Toast.makeText(this._getApplicationContext(), R.string._item, Toast.LENGTH_SHORT).show();

15:屏幕显示

程序中默的显示是带有标题栏和系统信息栏的,有的时候,这很影响程序界面的美观。手机默认的是竖屏,或与感应器状态相关,为了某种效果,我们的程序需要限制使用横屏或竖屏。以下的代码就解决了上述问题。

//设置为无标题栏
requestWindowFeature(Window.FEATURE_NO_TITLE);
//设置为全屏模式
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//设置为横屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

16:Intent传参

当Activity与Activity/Service(或其它情况)有时与要进行参数传递,最常用也是最简单的方式就是通过Intent来处理。
看如下代码:
Intent intent = new Intent(…);
Bundle bundle = new Bundle();
bundle.putString(“NAME”, “zixuan”);
intent.putExtras(bundle);
context.startActivity(intent); 或 context.startService(intent);

当然,有传送就有接收,接收也很简单,如:
Bundle bunde = intent.getExtras();
String name = bunde.getInt(“NAME”);
当然参数KEY要与传送时的参数一致。

17:获取手机号

在j2me中,根本没有办法获取用户的手机号码,就连获取手机串号(IMEI)都基本上无法实现,然后在android手机上一切都是如此的简单,看代码:
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String imei = tm.getDeviceId();
String tel = tm.getLine1Number();
看来,android的确加速了j2me的消亡。

18:振动器

总感觉手机上的振动器没有多大用处(当然静音模式下的振铃很有用),但还是顺带着说一下吧,只有两行代码:
1、获取振动服务的实例
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
2、设置振动时长,单位当然也是ms
vibrator.vibrate(1000);
如果你觉得这样过去单调的话,可以设个节奏:
vibrator.vibrate(new long[]{10, 100, 20, 200}, -1);
两个参数,习惯告诉我第一个是节奏,第二个是重复次数,可事实并没有这么简单,我翻译不好,大家还是看原文吧:
public void vibrate (long[] pattern, int repeat)
pattern: an array of longs of times to turn the vibrator on or off.
repeat: the index into pattern at which to repeat, or -1 if you don’t want to repeat.
google喜欢弄些技巧,我却觉得这里有点弄巧成拙了。

19:闹钟管理

最近看了一下Android的闹钟管理类(AlarmManager),真不错误,强大又简单,代码如下:

1)、建立一个AlarmReceiver继承入BroadcastReceiver,并在AndroidManifest.xml声明
public static class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, “闹钟提示:时间到!”, Toast.LENGTH_LONG).show();
}
}

2)、建立Intent和PendingIntent,来调用目标组件。
Intent intent = new Intent(this, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

3)、设置闹钟
获取闹钟管理的实例:
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
设置单次闹钟:
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (5*1000), pendingIntent);
设置周期闹钟:
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (10*1000), (24*60*60*1000), pendingIntent);

20:开机自启动

1).定义一个BroadcastReceiver

public class BootReceiver extends BroadcastReceiver {
public void onReceive(Context ctx, Intent intent) {
Log.d(“BootReceiver”, “system boot completed”);
//start activity
String action=”android.intent.action.MAIN”;
String category=”android.intent.category.LAUNCHER”;
Intent myi=new Intent(ctx,CustomDialog.class);
myi.setAction(action);
myi.addCategory(category);
myi.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(myi);
//start service
Intent s=new Intent(ctx,MyService.class);
ctx.startService(s);
}
}

2).配置Receiver的许可,允许接收系统启动消息,在AndroidManifest.xml中:

3).配置Receiver,可以接收系统启动消息,在AndroidManifest.xml中






4).启动模拟器,可以看到系统启动后,弹出一个对话框。

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lxh2808/archive/2010/10/30/5976351.aspx