标签:java etl context dma format activity nts roi tst
package com.game.utils; import android.app.Activity; import android.content.ClipData; import android.content.ClipDescription; import android.content.ClipboardManager; import android.content.Context; import android.os.Handler; import android.os.Looper; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.NetworkInterface; import java.util.Collections; import java.util.List; public class GameUtils { public byte[] ReadBytes(Activity activity, String path) { InputStream is = null; try { is = activity.getAssets().open(path); }catch (IOException e){ e.printStackTrace(); } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte buf[] = new byte [1024]; int len; try { while ((len = is.read(buf)) != -1) { outputStream.write (buf, 0, len); } outputStream.close(); is.close(); } catch (IOException e) { e.printStackTrace(); } return outputStream.toByteArray(); } public static ClipboardManager clipboard = null; // 向剪贴板中添加文本 public void copyTextToClipboard(final Context activity, final String str) throws Exception { if(Looper.myLooper() == null) { Looper.prepare(); } Handler handler = new Handler(); clipboard = (ClipboardManager) activity.getSystemService(Activity.CLIPBOARD_SERVICE); if (clipboard != null && clipboard.hasPrimaryClip() && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { ClipData textCd = ClipData.newPlainText("data", str); clipboard.setPrimaryClip(textCd); } handler.getLooper().quit(); } // 从剪贴板中获取文本 public String getTextFromClipboard(final Context activity) throws Exception { if(Looper.myLooper() == null) { Looper.prepare(); Looper.myLooper(); } StringBuilder res1 = new StringBuilder(); //Handler handler = new Handler(); clipboard = (ClipboardManager) activity.getSystemService(Activity.CLIPBOARD_SERVICE); //if (clipboard != null && clipboard.hasPrimaryClip() && clipboard.getPrimaryClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { if (clipboard != null && clipboard.hasPrimaryClip()) { ClipData cdText = clipboard.getPrimaryClip(); ClipData.Item item = cdText.getItemAt(0); res1.append(item.getText().toString()); } else { res1.append("no key"); } //handler.getLooper().quit(); return res1.toString(); } /** * 获取MAC地址 * @return */ public String getAndroidMac(final Context activity) { try { List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface nif : all) { if (!nif.getName().equalsIgnoreCase("wlan0")) continue; byte[] macBytes = nif.getHardwareAddress(); if (macBytes == null) { return null; } StringBuilder res1 = new StringBuilder(); for (byte b : macBytes) { res1.append(String.format("%02X:", b)); } if (res1.length() > 0) { res1.deleteCharAt(res1.length() - 1); } return res1.toString(); } } catch (Exception ex) { ex.printStackTrace(); } return null; } }
标签:java etl context dma format activity nts roi tst
原文地址:https://www.cnblogs.com/dabiaoge/p/9016147.html