1 package com.android.nfc.handover; 2 3 import android.app.Activity; 4 import android.app.AlertDialog; 5 import android.bluetooth.BluetoothDevice; 6 import android.content.DialogInterface; 7 import android.content.Intent; 8 import android.content.res.Resources; 9 import android.os.Bundle; 10 11 import com.android.nfc.R; 12 13 public class ConfirmConnectActivity extends Activity { 14 BluetoothDevice mDevice; 15 @Override 16 protected void onCreate(Bundle savedInstanceState) { 17 super.onCreate(savedInstanceState); 18 AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_DARK); 19 Intent launchIntent = getIntent(); 20 mDevice = launchIntent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 21 if (mDevice == null) finish(); 22 Resources res = getResources(); 23 String deviceName = mDevice.getName() != null ? mDevice.getName() : ""; 24 String confirmString = String.format(res.getString(R.string.confirm_pairing), deviceName); 25 builder.setMessage(confirmString) 26 .setCancelable(false) 27 .setPositiveButton(res.getString(R.string.pair_yes), 28 new DialogInterface.OnClickListener() { 29 public void onClick(DialogInterface dialog, int id) { 30 Intent allowIntent = new Intent(BluetoothHeadsetHandover.ACTION_ALLOW_CONNECT); 31 allowIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); 32 sendBroadcast(allowIntent); 33 ConfirmConnectActivity.this.finish(); 34 } 35 }) 36 .setNegativeButton(res.getString(R.string.pair_no), 37 new DialogInterface.OnClickListener() { 38 public void onClick(DialogInterface dialog, int id) { 39 Intent denyIntent = new Intent(BluetoothHeadsetHandover.ACTION_DENY_CONNECT); 40 denyIntent.putExtra(BluetoothDevice.EXTRA_DEVICE, mDevice); 41 sendBroadcast(denyIntent); 42 ConfirmConnectActivity.this.finish(); 43 } 44 }); 45 AlertDialog alert = builder.create(); 46 alert.show(); 47 } 48 } 49