Example usage for android.content Intent setClassName

List of usage examples for android.content Intent setClassName

Introduction

In this page you can find the example usage for android.content Intent setClassName.

Prototype

public @NonNull Intent setClassName(@NonNull String packageName, @NonNull String className) 

Source Link

Document

Convenience for calling #setComponent with an explicit application package name and class name.

Usage

From source file:com.linkbubble.Settings.java

public void updateBrowsers() {
    if (mBrowsers == null) {
        mBrowsers = new Vector<Intent>();
        mBrowserPackageNames = new ArrayList<String>();
    } else {/* ww w  .ja v  a2 s .  c o  m*/
        mBrowsers.clear();
        mBrowserPackageNames.clear();
    }
    PackageManager packageManager = mContext.getPackageManager();
    Intent queryIntent = new Intent();
    queryIntent.setAction(Intent.ACTION_VIEW);
    queryIntent.setData(Uri.parse("http://www.fdasfjsadfdsfas.com")); // Something stupid that no non-browser app will handle
    List<ResolveInfo> resolveInfos = packageManager.queryIntentActivities(queryIntent,
            PackageManager.GET_RESOLVED_FILTER);
    String fallbackDefaultBrowserPackageName = null;
    String fallbackDefaultBrowserActivityClassName = null;
    for (ResolveInfo resolveInfo : resolveInfos) {
        IntentFilter filter = resolveInfo.filter;
        if (filter != null && filter.hasAction(Intent.ACTION_VIEW)
                && filter.hasCategory(Intent.CATEGORY_BROWSABLE)) {
            // Ignore LinkBubble from this list
            if (resolveInfo.activityInfo.packageName.equals(BuildConfig.APPLICATION_ID)) {
                mLinkBubbleEntryActivityResolveInfo = resolveInfo;
            } else if (Util.isValidBrowserPackageName(resolveInfo.activityInfo.packageName)) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setClassName(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
                mBrowsers.add(intent);
                mBrowserPackageNames.add(resolveInfo.activityInfo.packageName);
                if (resolveInfo.activityInfo.packageName
                        .equals(mContext.getResources().getString(R.string.tab_based_browser_id_name))) {
                    fallbackDefaultBrowserPackageName = resolveInfo.activityInfo.packageName;
                    fallbackDefaultBrowserActivityClassName = resolveInfo.activityInfo.name;
                }
            }
        }
    }

    String defaultBrowserPackage = mSharedPreferences.getString(PREFERENCE_DEFAULT_BROWSER_PACKAGE_NAME, null);
    //String rightConsumeBubblePackageName = mSharedPreferences.getString(PREFERENCE_RIGHT_CONSUME_BUBBLE_PACKAGE_NAME, null);
    String leftConsumeBubblePackageName = mSharedPreferences
            .getString(PREFERENCE_LEFT_CONSUME_BUBBLE_PACKAGE_NAME, null);

    if (fallbackDefaultBrowserPackageName != null) {
        try {
            ApplicationInfo applicationInfo = packageManager
                    .getApplicationInfo(fallbackDefaultBrowserPackageName, 0);
            String defaultBrowserLabel = packageManager.getApplicationLabel(applicationInfo).toString();

            if (defaultBrowserPackage == null || !doesPackageExist(packageManager, defaultBrowserPackage)) {
                SharedPreferences.Editor editor = mSharedPreferences.edit();
                editor.putString(PREFERENCE_DEFAULT_BROWSER_LABEL, defaultBrowserLabel);
                editor.putString(PREFERENCE_DEFAULT_BROWSER_PACKAGE_NAME, fallbackDefaultBrowserPackageName);
                editor.commit();
            }
            if (leftConsumeBubblePackageName != null
                    && !doesPackageExist(packageManager, leftConsumeBubblePackageName)) {
                setConsumeBubble(Constant.BubbleAction.ConsumeLeft, Constant.ActionType.View,
                        defaultBrowserLabel, fallbackDefaultBrowserPackageName,
                        fallbackDefaultBrowserActivityClassName);
            }

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.igniva.filemanager.fragments.Main.java

public void bindDrive(String account) {
    Intent i = new Intent();
    i.setClassName("com.igniva.filemanager.driveplugin", "com.igniva.filemanager.driveplugin.MainService");
    i.putExtra("account", account);
    try {/*from   w w w  . j  av  a 2 s  .  c  o  m*/
        getActivity().bindService((i), mConnection, Context.BIND_AUTO_CREATE);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.mantz_it.rfanalyzer.ui.activity.MainActivity.java

/**
 * Will open the IQ Source instance./*from  ww w.j a  va  2s . c o  m*/
 * Note: some sources need special treatment on opening, like the rtl-sdr source.
 *
 * @return true on success; false on error
 */
public boolean openSource() {
    int sourceType = Integer.parseInt(preferences.getString(getString(R.string.pref_sourceType), "1"));

    switch (sourceType) {
    case FILE_SOURCE:
        if (source != null && source instanceof FileIQSource) {
            // Check for the READ_EXTERNAL_STORAGE permission:
            if (ContextCompat.checkSelfPermission(this,
                    "android.permission.READ_EXTERNAL_STORAGE") != PackageManager.PERMISSION_GRANTED) {
                // request permission:
                ActivityCompat.requestPermissions(this,
                        new String[] { "android.permission.READ_EXTERNAL_STORAGE" },
                        PERMISSION_REQUEST_FILE_SOURCE_READ_FILES);
                return true; // return and wait for the response (is handled in onRequestPermissionResult())
            } else {
                return source.open(this, this);
            }
        } else {
            Log.e(LOGTAG, "openSource: sourceType is FILE_SOURCE, but source is null or of other type.");
            return false;
        }
    case HACKRF_SOURCE:
        if (source != null && source instanceof HackrfSource)
            return source.open(this, this);
        else {
            Log.e(LOGTAG, "openSource: sourceType is HACKRF_SOURCE, but source is null or of other type.");
            return false;
        }
    case RTLSDR_SOURCE:
        if (source != null && source instanceof RtlsdrSource) {
            // todo: let RTL-SDR manage it dependencies
            // We might need to start the driver:
            if (!preferences.getBoolean(getString(R.string.pref_rtlsdr_externalServer), false)) {
                // start local rtl_tcp instance:
                try {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setClassName("marto.rtl_tcp_andro", "com.sdrtouch.rtlsdr.DeviceOpenActivity");
                    intent.setData(Uri.parse("iqsrc://-a 127.0.0.1 -p 1234 -n 1"));
                    startActivityForResult(intent, RTL2832U_RESULT_CODE);
                } catch (ActivityNotFoundException e) {
                    Log.e(LOGTAG, "createSource: RTL2832U is not installed");

                    // Show a dialog that links to the play market:
                    new AlertDialog.Builder(this).setTitle("RTL2832U driver not installed!")
                            .setMessage(
                                    "You need to install the (free) RTL2832U driver to use RTL-SDR dongles.")
                            .setPositiveButton("Install from Google Play", (dialog, whichButton) -> {
                                Intent marketIntent = new Intent(Intent.ACTION_VIEW,
                                        Uri.parse("market://details?id=marto.rtl_tcp_andro"));
                                startActivity(marketIntent);
                            }).setNegativeButton("Cancel", (dialog, whichButton) -> {
                                // do nothing
                            }).show();
                    return false;
                }
            }

            return source.open(this, this);
        } else {
            Log.e(LOGTAG, "openSource: sourceType is RTLSDR_SOURCE, but source is null or of other type.");
            return false;
        }
    case HIQSDR_SOURCE:
        if (source != null && source instanceof HiqsdrSource)
            return source.open(this, this);
        else {
            Log.e(LOGTAG, "openSource: sourceType is HIQSDR_SOURCE, but source is null or of other type.");
            return false;
        }

    default:
        Log.e(LOGTAG, "openSource: Invalid source type: " + sourceType);
        return false;
    }
}

From source file:org.eclipse.paho.android.service.MqttConnection.java

private void parseMqttMessageV2(String topic, MqttMessage mqttMessage) throws Exception {
    Log.v("mqtt", "parseMqttMessageV2");
    Context ctx = NanuService.getContext();
    byte origMqttMsgByte[] = mqttMessage.getPayload();
    int mqttIndex = 0;
    boolean processVTagSuccess = false;

    boolean processPTagSuccess = false;
    long mqttPacketValue = 0;

    boolean processTTagSuccess = false;
    long mqttTimestampValue = 0;

    boolean processLTagSuccess = false;
    int mqttMsgLengthValue = 0;

    boolean processMTagSuccess = false;
    String mqttMessageValue = "";
    String mqttMembersValue = "";

    boolean processGTagSuccess = false;
    long mqttGroupIDValue = 0;

    boolean processSTagSuccess = false;
    String mqttSubjectValue = "";

    boolean processCTagSuccess = false;
    int mqttMemberCountValue = 0;

    boolean processNTagSuccess = false;
    int mqttAdminCountValue = 0;

    boolean processATagSuccess = false;
    String mqttAdminsValue = "";

    String[] topicArray = topic.split("\\/");

    String sender = topicArray[2];
    if (topicArray.length == 4) {
        processGTagSuccess = true;/*w ww .ja v a 2 s .c o m*/
        try {
            mqttGroupIDValue = Long.parseLong(topicArray[3].toString().trim());
        } catch (NumberFormatException nfe) {
            processGTagSuccess = false;
            nfe.printStackTrace();
        }

        if (mqttGroupIDValue == 0) {
            try {
                mqttGroupIDValue = Long.valueOf(topicArray[3].trim());
            } catch (Exception err) {
                processGTagSuccess = false;
                err.printStackTrace();
            }
        }
    }

    String mqttMsgDateValue = "";
    for (int indexMqttCounter = 0; indexMqttCounter < origMqttMsgByte.length; indexMqttCounter++) {
        /*       Log.v(SettingsManager.TAG, "MqttService origMqttMsgByte[" + indexMqttCounter + "] = " + origMqttMsgByte[indexMqttCounter]); */
    }

    for (int indexMqttCounter = 0; indexMqttCounter < origMqttMsgByte.length; indexMqttCounter++) {
        if (indexMqttCounter == 0) {
            mqttIndex = indexMqttCounter;
            long mqttVTag = getMqttTag(origMqttMsgByte, mqttIndex);
            if (mqttVTag != -1) {
                if (mqttVTag == 86) // "V"
                {
                    processVTagSuccess = true;
                    mqttIndex = mqttIndex + 2;
                } else {
                    processVTagSuccess = false;
                    break;
                }
            }
        } else {
            if (mqttIndex == indexMqttCounter) {
                long mqttTag = getMqttTag(origMqttMsgByte, mqttIndex);
                if (mqttTag != -1) {
                    if (mqttTag == 80) /* "P" */ {
                        mqttIndex = mqttIndex + 1;
                        long mPValue = origMqttMsgByte[mqttIndex];
                        mqttPacketValue = mPValue;
                        mqttIndex = mqttIndex + 1;
                        processPTagSuccess = true;
                    } else if (mqttTag == 84) /* "T" */ {
                        mqttIndex = mqttIndex + 1;
                        byte timeStampArray[] = new byte[8];
                        for (int i = 0; i < 8; i++) {
                            timeStampArray[i] = origMqttMsgByte[mqttIndex + i];
                        }
                        mqttTimestampValue = ByteBuffer.wrap(timeStampArray).order(ByteOrder.LITTLE_ENDIAN)
                                .getLong();

                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                        String messageYear = sdf.format(mqttTimestampValue);
                        if (messageYear.length() != 4) {
                            mqttTimestampValue = ByteBuffer.wrap(timeStampArray).order(ByteOrder.BIG_ENDIAN)
                                    .getLong();
                        }
                        SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String messageDate = sdfDate.format(mqttTimestampValue);
                        processTTagSuccess = true;
                        mqttIndex = mqttIndex + 8;
                    } else if (mqttTag == 76) /* "L" */ {
                        if (processPTagSuccess) {
                            if (mqttPacketValue == -128 || (mqttPacketValue == -117)
                                    || (mqttPacketValue == -115) || (mqttPacketValue == -126)) {
                                mqttIndex = mqttIndex + 1;
                                mqttMsgLengthValue = origMqttMsgByte[mqttIndex];
                                processLTagSuccess = true;
                                mqttIndex = mqttIndex + 1;
                            } else if (mqttPacketValue == 0) {
                                mqttIndex = mqttIndex + 1;
                                byte msgLengthArray[] = new byte[4];
                                for (int i = 0; i < 4; i++) {
                                    msgLengthArray[i] = origMqttMsgByte[mqttIndex + i];
                                }
                                mqttMsgLengthValue = ByteBuffer.wrap(msgLengthArray)
                                        .order(ByteOrder.LITTLE_ENDIAN).getInt();
                                processLTagSuccess = true;
                                mqttIndex = mqttIndex + 4;
                            }
                        }
                    } else if (mqttTag == 77) /* "M" */ {
                        if (processPTagSuccess) {
                            if ((mqttPacketValue == -128) || (mqttPacketValue == -124)
                                    || (mqttPacketValue == -126) || (mqttPacketValue == -117)) {

                                if (processCTagSuccess) {
                                    mqttIndex = mqttIndex + 1;
                                    for (int i = 0; i < mqttMemberCountValue; i++) {
                                        byte groupMembersArray[] = new byte[8];
                                        for (int j = 0; j < 8; j++) {
                                            groupMembersArray[j] = origMqttMsgByte[mqttIndex + j];
                                        }
                                        long participants = ByteBuffer.wrap(groupMembersArray)
                                                .order(ByteOrder.LITTLE_ENDIAN).getLong();
                                        mqttIndex = mqttIndex + 8;
                                        if (i == (mqttMemberCountValue - 1)) {
                                            mqttMembersValue = mqttMembersValue + participants;
                                        } else {
                                            mqttMembersValue = mqttMembersValue + participants + ",";
                                        }
                                    }
                                    processMTagSuccess = true;
                                } else {
                                    break;
                                }
                            } else if (mqttPacketValue == 0) {
                                if (processLTagSuccess) {
                                    mqttIndex = mqttIndex + 1;
                                    if (mqttMsgLengthValue > 0) {
                                        byte messageArray[] = null;
                                        try {
                                            messageArray = new byte[mqttMsgLengthValue];
                                        } catch (Exception err) {
                                            err.printStackTrace();
                                            processMTagSuccess = false;
                                            break;
                                        }

                                        for (int i = 0; i < mqttMsgLengthValue; i++) {
                                            messageArray[i] = origMqttMsgByte[mqttIndex + i];
                                        }
                                        mqttMessageValue = new String(messageArray);
                                        processMTagSuccess = true;
                                        mqttIndex = mqttIndex + mqttMsgLengthValue + 1;
                                    }
                                } else {
                                    break;
                                }
                            }
                        }
                    } else if (mqttTag == 71) /* "G" */ {
                        mqttIndex = mqttIndex + 1;
                        byte groupIDArray[] = new byte[8];
                        for (int i = 0; i < 8; i++) {
                            groupIDArray[i] = origMqttMsgByte[mqttIndex + i];
                        }
                        mqttGroupIDValue = ByteBuffer.wrap(groupIDArray).order(ByteOrder.LITTLE_ENDIAN)
                                .getLong();
                        processGTagSuccess = true;
                        mqttIndex = mqttIndex + 8;
                    } else if (mqttTag == 83) /* "S" */ {
                        if (processLTagSuccess) {
                            mqttIndex = mqttIndex + 1;
                            if (mqttMsgLengthValue > 0) {
                                byte subjectArray[] = null;
                                try {
                                    subjectArray = new byte[mqttMsgLengthValue];
                                } catch (Exception err) {
                                    err.printStackTrace();
                                    processSTagSuccess = false;
                                    break;
                                }
                                for (int i = 0; i < mqttMsgLengthValue; i++) {
                                    subjectArray[i] = origMqttMsgByte[mqttIndex + i];
                                }
                                mqttSubjectValue = new String(subjectArray);
                                processSTagSuccess = true;
                                mqttIndex = mqttIndex + mqttMsgLengthValue;
                            }
                        } else {
                            break;
                        }
                    } else if (mqttTag == 67) /* "C" */ {
                        mqttIndex = mqttIndex + 1;
                        mqttMemberCountValue = origMqttMsgByte[mqttIndex];
                        processCTagSuccess = true;
                        mqttIndex = mqttIndex + 1;
                    } else if (mqttTag == 78) /* "N" */ {
                        mqttIndex = mqttIndex + 1;
                        mqttAdminCountValue = origMqttMsgByte[mqttIndex];
                        processNTagSuccess = true;
                        mqttIndex = mqttIndex + 1;
                    } else if (mqttTag == 65) /* "A" */ {
                        if (processPTagSuccess) {
                            if (mqttPacketValue == -117) {
                                if (processNTagSuccess) {
                                    mqttIndex = mqttIndex + 1;
                                    for (int i = 0; i < mqttAdminCountValue; i++) {
                                        byte groupAdminsArray[] = new byte[8];
                                        for (int j = 0; j < 8; j++) {
                                            groupAdminsArray[j] = origMqttMsgByte[mqttIndex + j];
                                        }
                                        long admins = ByteBuffer.wrap(groupAdminsArray)
                                                .order(ByteOrder.LITTLE_ENDIAN).getLong();
                                        mqttIndex = mqttIndex + 8;
                                        if (i == (mqttAdminCountValue - 1)) {
                                            mqttAdminsValue = mqttAdminsValue + admins;
                                        } else {
                                            mqttAdminsValue = mqttAdminsValue + admins + ",";
                                        }
                                    }
                                    processATagSuccess = true;
                                } else {
                                    break;
                                }
                            }
                        }
                    } else {
                        break;
                    }
                } else {
                    break;
                }
            }
        }
    }

    if (!processVTagSuccess) {
        return;
    }

    PowerManager pm = (PowerManager) ctx.getSystemService(Context.POWER_SERVICE);
    boolean isScreenOn = pm.isScreenOn();
    if (isScreenOn == false) {
        WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
                | PowerManager.ON_AFTER_RELEASE, "MyLock");
        if (wl.isHeld()) {
            wl.release();
        }
        wl.acquire(10000);
        WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyCpuLock");
        if (wl_cpu.isHeld()) {
            wl_cpu.release();
        }
        wl_cpu.acquire(10000);
    }

    String message = mqttMessageValue;
    Log.v("mqtt", "from: " + sender);
    Log.v("mqtt", "message: " + message);
    Intent intent = new Intent();
    intent.setClassName(ctx, "org.eclipse.paho.android.service.sample.MainActivity");
    intent.putExtra("handle", clientHandle);
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) ctx.getSystemService(ns);
    int messageNotificationId = 1;
    mNotificationManager.cancel(messageNotificationId);
    Calendar.getInstance().getTime().toString();
    long when = System.currentTimeMillis();
    String ticker = sender + " " + mqttMessageValue;
    PendingIntent pendingIntent = PendingIntent.getActivity(ctx, 3, intent, 0);
    NotificationCompat.Builder notificationCompat = new NotificationCompat.Builder(ctx);
    notificationCompat.setAutoCancel(true).setContentTitle(sender).setContentIntent(pendingIntent)
            .setContentText(mqttMessageValue).setTicker(ticker).setWhen(when)
            .setSmallIcon(R.drawable.ic_launcher);

    //  Notification notification = notificationCompat.build();
    Bitmap iconLarge = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx)
            .setSmallIcon(R.drawable.ic_launcher).setLargeIcon(iconLarge).setContentTitle(sender)
            .setContentText(mqttMessageValue);

    mBuilder.setContentIntent(pendingIntent);
    mBuilder.setTicker(message);
    mBuilder.setAutoCancel(true);
    mBuilder.setDefaults(
            Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS);
    mNotificationManager.notify(messageNotificationId, mBuilder.build());
}

From source file:com.jtechme.apphub.FDroidApp.java

public void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
    if (resultCode == Activity.RESULT_CANCELED)
        return;//  w  ww  .j a va2  s.c o m
    String bluetoothPackageName = null;
    String className = null;
    boolean found = false;
    Intent sendBt = null;
    try {
        PackageManager pm = getPackageManager();
        ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        sendBt = new Intent(Intent.ACTION_SEND);
        // The APK type is blocked by stock Android, so use zip
        // sendBt.setType("application/vnd.android.package-archive");
        sendBt.setType("application/zip");
        sendBt.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + appInfo.publicSourceDir));
        // not all devices have the same Bluetooth Activities, so
        // let's find it
        for (ResolveInfo info : pm.queryIntentActivities(sendBt, 0)) {
            bluetoothPackageName = info.activityInfo.packageName;
            if ("com.android.bluetooth".equals(bluetoothPackageName)
                    || "com.mediatek.bluetooth".equals(bluetoothPackageName)) {
                className = info.activityInfo.name;
                found = true;
                break;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Could not get application info to send via bluetooth", e);
        found = false;
    }
    if (sendBt != null) {
        if (found) {
            sendBt.setClassName(bluetoothPackageName, className);
            activity.startActivity(sendBt);
        } else {
            Toast.makeText(this, R.string.bluetooth_activity_not_found, Toast.LENGTH_SHORT).show();
            activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send)));
        }
    }
}

From source file:com.dzt.musicplay.player.AudioService.java

private void updateWidgetCover(Context context) {
    Intent i = new Intent();
    i.setClassName(WIDGET_PACKAGE, WIDGET_CLASS);
    i.setAction(ACTION_WIDGET_UPDATE_COVER);

    Bitmap cover = hasCurrentMedia() ? AudioUtil.getCover(this, getCurrentMedia(), 64) : null;
    i.putExtra("cover", cover);

    sendBroadcast(i);//from w w w  .j  av a2  s .c o  m
}

From source file:com.dzt.musicplay.player.AudioService.java

private void updateWidgetPosition(Context context, float pos) {
    // no more than one widget update for each 1/50 of the song
    long timestamp = Calendar.getInstance().getTimeInMillis();
    if (!hasCurrentMedia() || timestamp - mWidgetPositionTimestamp < getCurrentMedia().getLength() / 50)
        return;//w w  w  . jav  a  2 s .co  m

    updateWidgetState(context);

    mWidgetPositionTimestamp = timestamp;
    Intent i = new Intent();
    i.setClassName(WIDGET_PACKAGE, WIDGET_CLASS);
    i.setAction(ACTION_WIDGET_UPDATE_POSITION);
    i.putExtra("position", pos);
    sendBroadcast(i);
}

From source file:com.dzt.musicplay.player.AudioService.java

private void updateWidgetState(Context context) {
    Intent i = new Intent();
    i.setClassName(WIDGET_PACKAGE, WIDGET_CLASS);
    i.setAction(ACTION_WIDGET_UPDATE);//from w w  w.  ja  va 2 s .c o m

    if (hasCurrentMedia()) {
        i.putExtra("title", getCurrentMedia().getTitle());
        i.putExtra("artist", getCurrentMedia().getArtist());
    } else {
        i.putExtra("title", context.getString(R.string.widget_name));
        i.putExtra("artist", "");
    }
    i.putExtra("isplaying", mLibVLC.isPlaying());

    sendBroadcast(i);
}

From source file:org.fdroid.fdroid.FDroidApp.java

public void sendViaBluetooth(Activity activity, int resultCode, String packageName) {
    if (resultCode == Activity.RESULT_CANCELED) {
        return;/*from  w w  w.j  a v a 2  s  . c om*/
    }
    String bluetoothPackageName = null;
    String className = null;
    boolean found = false;
    Intent sendBt = null;
    try {
        PackageManager pm = getPackageManager();
        ApplicationInfo appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        sendBt = new Intent(Intent.ACTION_SEND);
        // The APK type is blocked by stock Android, so use zip
        // sendBt.setType("application/vnd.android.package-archive");
        sendBt.setType("application/zip");
        sendBt.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + appInfo.publicSourceDir));
        // not all devices have the same Bluetooth Activities, so
        // let's find it
        for (ResolveInfo info : pm.queryIntentActivities(sendBt, 0)) {
            bluetoothPackageName = info.activityInfo.packageName;
            if ("com.android.bluetooth".equals(bluetoothPackageName)
                    || "com.mediatek.bluetooth".equals(bluetoothPackageName)) {
                className = info.activityInfo.name;
                found = true;
                break;
            }
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Could not get application info to send via bluetooth", e);
        found = false;
    }
    if (sendBt != null) {
        if (found) {
            sendBt.setClassName(bluetoothPackageName, className);
            activity.startActivity(sendBt);
        } else {
            Toast.makeText(this, R.string.bluetooth_activity_not_found, Toast.LENGTH_SHORT).show();
            activity.startActivity(Intent.createChooser(sendBt, getString(R.string.choose_bt_send)));
        }
    }
}

From source file:com.fvd.nimbus.BrowseActivity.java

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    drawer.closeDrawer(GravityCompat.START);
    Intent ip = new Intent();
    switch (arg2) {
    case 0:/*ww  w.ja v a  2  s  .c om*/
        ip.putExtra("act", "photo");
        ip.setClassName("com.fvd.nimbus", "com.fvd.nimbus.PaintActivity");
        startActivity(ip);
        break;
    case 1:
        ip.putExtra("act", "picture");
        ip.setClassName("com.fvd.nimbus", "com.fvd.nimbus.PaintActivity");
        startActivity(ip);
        break;
    case 2:
        ip.setClassName("com.fvd.nimbus", "com.fvd.nimbus.ChoosePDFActivity");
        startActivity(ip);
        break;

    default:
        break;
    }
    overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
    finish();

}