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);
//创建电话管理TelephonyManager tm = (TelephonyManager)//与手机建立连接activity.getSystemService(Context.TELEPHONY_SERVICE);//获取手机号码String phoneId = tm.getLine1Number();//记得在manifest file中添加 <uses-permission android:name="android.permission.READ_PHONE_STATE" />//程序在模拟器上无法实现,必须连接手机
// in strings.xml..<string name="my_text">Thanks for visiting %s. You age is %d!</string> // and in the java code:String.format(getString(R.string.my_text), "oschina", 33);
/** 全屏设置,隐藏窗口所有装饰 */requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
<activity android:name=".Login.NetEdit" android:label="@string/label_net_Edit" android:screenOrientation="portrait" android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"> <intent-filter> <action android:name="android.intent.Net_Edit" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
在AndroidManifest.xml中配置Activity节点是配置theme如下:
android:theme="@android:style/Theme.Dialog"
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 增加权限:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
public static boolean isIntentAvailable(Context context, String action) { final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); return list.size() > 0; }
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); }
Intent i = new Intent(Intent.ACTION_SEND); //i.setType("text/plain"); //模拟器请使用这行i.setType("message/rfc822") ; // 真机上使用这行i.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]","[email protected]}); i.putExtra(Intent.EXTRA_SUBJECT,"subject goes here"); i.putExtra(Intent.EXTRA_TEXT,"body goes here"); startActivity(Intent.createChooser(i, "Select email application."));
Intent viewIntent = new Intent("android.intent.action.VIEW",Uri.parse("http://vaiyanzi.cnblogs.com")); startActivity(viewIntent);
String android_id = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
public String getLocalIpAddress() { try { for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration<InetAddress> 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; }
/** 获取存储卡路径 */ 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();
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; }
Intent intentBatteryUsage = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); startActivity(intentBatteryUsage);
ActivityManager mActivityManager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> mRunningProcess = mActivityManager.getRunningAppProcesses(); int i = 1;for (ActivityManager.RunningAppProcessInfo amProcess : mRunningProcess) { Log.e("homer Application", (i++) + " PID = " + amProcess.pid + "; processName = " + amProcess.processName); }