Constructor(Class<?> cls, Class<?>[] args) { try { Constructor<?> c = cls.getDeclaredConstructor(args); if (!c.isAccessible()) c.setAccessible(true); return c; } catch (Exception ex) { return null; } }
public static void ActivateBluetooth(Context c, View v) { try { //Play nice and use the system dialog for this c.startActivity(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)); } catch (ActivityNotFoundException ax) { ManualAskBluetoothActivate(c, v); } catch (AndroidRuntimeException ax) { ManualAskBluetoothActivate(c, v); } }毕业论文
private static void ManualAskBluetoothActivate(Context c, View v) { //If it fails, do this directly AlertDialog.Builder builder = new AlertDialog.Builder(c); builder.setCancelable(true); builder.setMessage(R.string.bluetooth_enable_question); builder.setTitle(R.string.bluetooth_enable_dialog_title);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { BluetoothAdapter.getDefaultAdapter().enable(); }} );
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { }} );
//If we are running in the IME, we need to do something special if (v != null) { AlertDialog dlg = builder.create();
Window window = dlg.getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.token = v.getWindowToken(); lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; window.setAttributes(lp); window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
dlg.show(); } else builder.show();
}
public static void DeactivateBluetooth(Context c) { AlertDialog.Builder dlg = new AlertDialog.Builder(c); dlg.setCancelable(true); dlg.setMessage(R.string.bluetooth_disable_question); dlg.setTitle(R.string.bluetooth_disable_dialog_title);
dlg.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { BluetoothAdapter.getDefaultAdapter().disable(); }} );
dlg.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { }} );
dlg.show(); }
//private static final int TYPE_RFCOMM = 1; //private static final int TYPE_SCO = 2; private static final int TYPE_L2CAP = 3;
上一页 [1] [2] [3] [4] [5] [6] 下一页
|