1、图片旋转

Bitmap bitmapOrg = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.moon);Matrix matrix = new Matrix();matrix.postRotate(-90);//旋转的角度 Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,                    bitmapOrg.getWidth(), bitmapOrg.getHeight(), matrix, true);BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);


2、获取手机号码

//创建电话管理TelephonyManager tm = (TelephonyManager)//与手机建立连接activity.getSystemService(Context.TELEPHONY_SERVICE);//获取手机号码String phoneId = tm.getLine1Number();//记得在manifest file中添加    android.permission.READ_PHONE_STATE" />//程序在模拟器上无法实现,必须连接手机


3.格式化string.xml 中的字符串

// in strings.xml..my_text">Thanks for visiting %s. You age is %d!          // and in the java code:String.format(getString(R.string.my_text), "oschina", 33);


4、android设置全屏的方法

A.在java代码中设置

/** 全屏设置,隐藏窗口所有装饰 */requestWindowFeature(Window.FEATURE_NO_TITLE);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                WindowManager.LayoutParams.FLAG_FULLSCREEN);

B、在AndroidManifest.xml中配置

.Login.NetEdit"  android:label="@string/label_net_Edit"           android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">android.intent.Net_Edit" />android.intent.category.DEFAULT" />


5、设置Activity为Dialog的形式

在AndroidManifest.xml中配置Activity节点是配置theme如下:

android:theme="@android:style/Theme.Dialog"


6、检查当前网络是否连上

ConnectivityManager con=(ConnectivityManager)getSystemService(Activity.CONNECTIVITY_SERVICE);   boolean wifi=con.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();  boolean internet=con.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting(); 

在AndroidManifest.xml 增加权限:

android.permission.ACCESS_NETWORK_STATE" />


7、检测某个Intent是否有效

public static boolean isIntentAvailable(Context context, String action) {    final PackageManager packageManager = context.getPackageManager();    final Intent intent = new Intent(action);    List list =            packageManager.queryIntentActivities(intent,                    PackageManager.MATCH_DEFAULT_ONLY);    return list.size() > 0;}


8、android 拨打电话

try {   Intent intent = new Intent(Intent.ACTION_CALL);   intent.setData(Uri.parse("tel:+110"));   startActivity(intent);} catch (Exception e) {   Log.e("SampleApp", "Failed to invoke call", e);}


9、android中发送Email

Intent i = new Intent(Intent.ACTION_SEND);  //i.setType("text/plain"); //模拟器请使用这行i.setType("message/rfc822") ; // 真机上使用这行i.putExtra(Intent.EXTRA_EMAIL, new String[]{"test@gmail.com","test@163.com});  i.putExtra(Intent.EXTRA_SUBJECT,"subject goes here");  i.putExtra(Intent.EXTRA_TEXT,"body goes here");  startActivity(Intent.createChooser(i, "Select email application."));


10、android中打开浏览器

Intent viewIntent = new     Intent("android.intent.action.VIEW",Uri.parse("http://vaiyanzi.cnblogs.com"));startActivity(viewIntent);


11、android 获取设备唯一标识码

String android_id = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);


12、android中获取IP地址

public String getLocalIpAddress() {    try {        for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {            NetworkInterface intf = en.nextElement();            for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {                InetAddress inetAddress = enumIpAddr.nextElement();                if (!inetAddress.isLoopbackAddress()) {                    return inetAddress.getHostAddress().toString();                }            }        }    } catch (SocketException ex) {        Log.e(LOG_TAG, ex.toString());    }    return null;}


13、android获取存储卡路径以及使用情况

/** 获取存储卡路径 */ File sdcardDir=Environment.getExternalStorageDirectory(); /** StatFs 看文件系统空间使用情况 */ StatFs statFs=new StatFs(sdcardDir.getPath()); /** Block 的 size*/ Long blockSize=statFs.getBlockSize(); /** 总 Block 数量 */ Long totalBlocks=statFs.getBlockCount(); /** 已使用的 Block 数量 */ Long availableBlocks=statFs.getAvailableBlocks(); 


14 android中添加新的联系人

private Uri insertContact(Context context, String name, String phone) {          ContentValues values = new ContentValues();       values.put(People.NAME, name);       Uri uri = getContentResolver().insert(People.CONTENT_URI, values);       Uri numberUri = Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);       values.clear();              values.put(Contacts.Phones.TYPE, People.Phones.TYPE_MOBILE);       values.put(People.NUMBER, phone);       getContentResolver().insert(numberUri, values);              return uri;}


15、查看电池使用情况

Intent intentBatteryUsage = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY);        startActivity(intentBatteryUsage);

更多相关文章

  1. Android(安卓)2.1 GPS定位和拍照功能代码
  2. android 获取和设置屏幕亮度
  3. Android(安卓)fragment中如何对listview添加监听事件
  4. ListView 实现像Android(安卓)Market那样 分页加载 滚动加载
  5. android6.0 netd设置dns
  6. 箭头函数的基础使用
  7. NPM 和webpack 的基础使用
  8. Python list sort方法的具体使用
  9. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程

随机推荐

  1. android 地图服务开发 INSTALL_FAILED_MI
  2. 本文是独立应用商店GetJar创始人兼CEO Il
  3. Android(安卓)微信支付
  4. ListView的Adapter使用 之 初学ArrayAdap
  5. [置顶] Android之SharedPreferences两个
  6. 处理JNI ERROR (app bug): accessed stal
  7. 使用zipalign对齐应用程序
  8. Android面试常客之Handler全解
  9. Android(安卓)应用中十大常见 UX 错误
  10. Android欢迎界面,一个Activity搞定