当前位置: 编程技术>移动开发
本页文章导读:
▪设立APN为cmnet源码 设置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/c.........
▪ sd卡有关 sd卡相关
Environment.getExternalStorageDirectory() 获取sd卡目录
配置文件:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_.........
▪ 图片转成圆角展示 图片转成圆角显示
1. ImageView image;image=(ImageView)findViewById(R.id.image); Resources res=getResources(); Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.farm); Bitmap bitmpa=toRoundCorner(bmp,5); image.setImageBitmap(bitmp.........
[1]设立APN为cmnet源码
来源: 互联网 发布时间: 2014-02-18
设置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);
}
}
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);
}
}
[2] sd卡有关
来源: 互联网 发布时间: 2014-02-18
sd卡相关
Environment.getExternalStorageDirectory() 获取sd卡目录
配置文件:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
[3] 图片转成圆角展示
来源: 互联网 发布时间: 2014-02-18
图片转成圆角显示
1. ImageView image;
image=(ImageView)findViewById(R.id.image);
Resources res=getResources();
Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.farm);
Bitmap bitmpa=toRoundCorner(bmp,5);
image.setImageBitmap(bitmpa);
2.public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
1. ImageView image;
image=(ImageView)findViewById(R.id.image);
Resources res=getResources();
Bitmap bmp=BitmapFactory.decodeResource(res, R.drawable.farm);
Bitmap bitmpa=toRoundCorner(bmp,5);
image.setImageBitmap(bitmpa);
2.public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
最新技术文章: