当前位置: 编程技术>移动开发
本页文章导读:
▪短信的收发简略Demo 短信的收发简单Demo
短信的发送:发送短信相当的简单,只需要几行代码,如下:参数phoneNumber和MsgStr均是String类型,表示接收方的电话号码和短信内容SmsManager sms = SmsManager.getDefault();
Pendin.........
▪ ubuntu-11.10-server-i386学习札记-网络基本配置 ubuntu-11.10-server-i386学习笔记-网络基本配置
1. 静态IP地址配置配置文件路径:/etc/network/interfacesauto loiface lo inet loopbackauto eth0iface eth0 inet staticaddress 192.168.0.24netmask 255.255.255.0network 192.168.0.0.........
▪ 圆角图片的处置和圆角按钮的动画 圆角图片的处理和圆角按钮的动画
/** * 把图片变成圆角 * @param bitmap 需要修改的图片 * @param pixels 圆角的弧度 * @return 圆角图片 .........
[1]短信的收发简略Demo
来源: 互联网 发布时间: 2014-02-18
短信的收发简单Demo
短信的发送:
发送短信相当的简单,只需要几行代码,如下:
参数phoneNumber和MsgStr均是String类型,表示接收方的电话号码和短信内容
短信的接收:
MainActivity:
MyReceiver:
AndroidManifest.xml
短信的发送:
发送短信相当的简单,只需要几行代码,如下:
参数phoneNumber和MsgStr均是String类型,表示接收方的电话号码和短信内容
SmsManager sms = SmsManager.getDefault(); PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(), 0); sms.sendTextMessage(phoneNumber, null, MsgStr, pi, null);
短信的接收:
MainActivity:
package com.amaker.sms; import android.app.Activity; import android.content.IntentFilter; import android.os.Bundle; public class MainActivity extends Activity { //接收短信的action public static final String MY_ACTION = "android.provider.Telephony.SMS_RECEIVED"; MyReceiver receiver = new MyReceiver(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } /** * 注册接收短信的广播接收器 * 这里采用了动态的方式注册,也可以在AndroidManifest.xml里静态注册 */ @Override protected void onResume() { super.onResume(); IntentFilter filter = new IntentFilter(); filter.addAction(MY_ACTION); registerReceiver(receiver, filter); } /** * 取消接收短信的广播接收器 */ @Override protected void onPause() { super.onPause(); unregisterReceiver(receiver); } }
MyReceiver:
package com.amaker.sms; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsMessage; import android.widget.Toast; public class MyReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { SmsMessage sm; Bundle bundle = intent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); SmsMessage[] messages = new SmsMessage[pdus.length]; if(bundle!=null){ for (int i = 0; i < pdus.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); } } for(SmsMessage currentMessage:messages){ sm = currentMessage; String number = sm.getDisplayOriginatingAddress(); String content = sm.getDisplayMessageBody(); Toast.makeText(context, number+":"+content, Toast.LENGTH_LONG).show(); } } }
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.amaker.sms" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <!--<!->添加发送短信与接收短信的权限</!> --> <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission> <uses-permission android:name="android.permission.SEND_SMS"></uses-permission> </manifest>
[2] ubuntu-11.10-server-i386学习札记-网络基本配置
来源: 互联网 发布时间: 2014-02-18
ubuntu-11.10-server-i386学习笔记-网络基本配置
1. 静态IP地址配置
配置文件路径:/etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.0.24
netmask 255.255.255.0
network 192.168.0.0
gateway 192.168.0.1
dns-nameservers 192.168.0.1 【不需要】
配置好后,重新启动网卡服务:sudo /etc/init.d/networking restart
查看IP地址: ifconifg
检查网络通不通:ping 222.221.200.68(随便找个公网地址ping、ping测试哈)
配置DNS域名解析
vi /etc/resolv.conf
至此网络常见配置完毕
1. 静态IP地址配置
配置文件路径:/etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.0.24
netmask 255.255.255.0
network 192.168.0.0
gateway 192.168.0.1
dns-nameservers 192.168.0.1 【不需要】
配置好后,重新启动网卡服务:sudo /etc/init.d/networking restart
查看IP地址: ifconifg
检查网络通不通:ping 222.221.200.68(随便找个公网地址ping、ping测试哈)
配置DNS域名解析
vi /etc/resolv.conf
至此网络常见配置完毕
[3] 圆角图片的处置和圆角按钮的动画
来源: 互联网 发布时间: 2014-02-18
圆角图片的处理和圆角按钮的动画
/**
* 把图片变成圆角
* @param bitmap 需要修改的图片
* @param pixels 圆角的弧度
* @return 圆角图片
*/
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(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
===================================================================
/**
* 将图片设置为圆角
*/
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(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
复制代码
当我们需要圆角的时候,调用这个方法,第一个参数是传入需要转化成圆角的图片,第二个参数是圆角的度数,数值越大,圆角越大
下面举个例子,有一个LinearLayout,想把它的背景图片设置成圆角
布局文件main.xml
1.<?xml version="1.0" encoding="utf-8"?>
2.<LinearLayout
3. xmlns:android="http://schemas.android.com/apk/res/android"
4. android:id="@+id/layout" android:orientation="vertical"
5. android:layout_width="wrap_content"
6. android:layout_height="wrap_content">
7.</LinearLayout>
.mInflater = LayoutInflater.from(this);
Drawable drawable = getResources().getDrawable(R.drawable.icon);
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable.getBitmap();
View view = mInflater.inflate(
R.layout.share_xiaohua_revert_lv_item_top, null);
ImageView mImageView = (ImageView) view
.findViewById(R.id.lv_xiaohua_image);
mImageView.setImageBitmap(toRoundCorner(bitmap, 30));
/**
* 把图片变成圆角
* @param bitmap 需要修改的图片
* @param pixels 圆角的弧度
* @return 圆角图片
*/
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(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
===================================================================
/**
* 将图片设置为圆角
*/
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(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
复制代码
当我们需要圆角的时候,调用这个方法,第一个参数是传入需要转化成圆角的图片,第二个参数是圆角的度数,数值越大,圆角越大
下面举个例子,有一个LinearLayout,想把它的背景图片设置成圆角
布局文件main.xml
1.<?xml version="1.0" encoding="utf-8"?>
2.<LinearLayout
3. xmlns:android="http://schemas.android.com/apk/res/android"
4. android:id="@+id/layout" android:orientation="vertical"
5. android:layout_width="wrap_content"
6. android:layout_height="wrap_content">
7.</LinearLayout>
.mInflater = LayoutInflater.from(this);
Drawable drawable = getResources().getDrawable(R.drawable.icon);
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable.getBitmap();
View view = mInflater.inflate(
R.layout.share_xiaohua_revert_lv_item_top, null);
ImageView mImageView = (ImageView) view
.findViewById(R.id.lv_xiaohua_image);
mImageView.setImageBitmap(toRoundCorner(bitmap, 30));
最新技术文章: