Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

How to know whether android shortcut already exist ex.


How to know whether android shortcut already exist
ex.

public void createShortcut(String url,String shortcutName, String type, Bitmap img)
    {           
        Intent shortcutIntent = new Intent();       
        shortcutIntent.setAction(Intent.ACTION_VIEW);

        if(type.equalsIgnoreCase("web")) {  

            Uri uri = Uri.parse(url);
            shortcutIntent.setData(uri);
        }
        else if (type.equalsIgnoreCase("app")) {

            Log.d("DEBUGGING", "Inside app installation " + url + " : " + group + " : " + shortcutName); 
            shortcutIntent.setClassName(url,group);
        }

        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
        addIntent.putExtra("duplicate", false);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, scaledBitmap);
      //  addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, R.drawable.ic_launcher);

        addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        sendBroadcast(addIntent);
//        Toast mToast = Toast.makeText(this, "shortcut created", Toast.LENGTH_SHORT);
//        mToast.show();

    }

How to programmatically pair a bluetooth device on Android

Programmatically pair a bluetooth device on Android:

public void pairDevice(BluetoothDevice device) {
        String ACTION_PAIRING_REQUEST = "android.bluetooth.device.action.PAIRING_REQUEST";
        Intent intent = new Intent(ACTION_PAIRING_REQUEST);
        String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
        intent.putExtra(EXTRA_DEVICE, device);
        String EXTRA_PAIRING_VARIANT = "android.bluetooth.device.extra.PAIRING_VARIANT";
        int PAIRING_VARIANT_PIN = 0;
        intent.putExtra(EXTRA_PAIRING_VARIANT, PAIRING_VARIANT_PIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

Intent intent = new Intent(BluetoothDevice.ACTION_PAIRING_REQUEST);
intent.putExtra(EXTRA_DEVICE, device);
int PAIRING_VARIANT_PIN = 272;
intent.putExtra(BluetoothDevice.EXTRA_PAIRING_VARIANT, PAIRING_VARIANT_PIN);
sendBroadcast(intent);

Intent intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS);
    startActivityForResult(intent, REQUEST_PAIR_DEVICE);