程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> java完成輸出輸入流代碼分享

java完成輸出輸入流代碼分享

編輯:關於JAVA

java完成輸出輸入流代碼分享。本站提示廣大學習愛好者:(java完成輸出輸入流代碼分享)文章只能為提供參考,不一定能成為您想要的結果。以下是java完成輸出輸入流代碼分享正文


本文實例總結了Android開辟經常使用經典代碼段。分享給年夜家供年夜家參考,詳細以下:

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中添加
<uses-permission
android:name="android.permission.READ_PHONE_STATE" />
//法式在模仿器上沒法完成,必需銜接手機

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

// 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);

4、android設置全屏的辦法

A.在java代碼中設置

/** 全屏設置,隱蔽窗口一切裝潢 */
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);

B、在AndroidManifest.xml中設置裝備擺設

<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>

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 增長權限:

<uses-permission android:name="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<ResolveInfo> 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[]{"[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."));

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<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;
}

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);

16、獲得過程號

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);
}

願望本文所述對年夜家Android法式設計有所贊助。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved