Example usage for android.content Intent CATEGORY_LAUNCHER

List of usage examples for android.content Intent CATEGORY_LAUNCHER

Introduction

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

Prototype

String CATEGORY_LAUNCHER

To view the source code for android.content Intent CATEGORY_LAUNCHER.

Click Source Link

Document

Should be displayed in the top-level launcher.

Usage

From source file:org.uguess.android.sysinfo.ProcessManager.java

void handleAction(final ProcessItem rap, int action) {
    Activity ctx = getActivity();//w  w  w  . jav  a 2  s.c  om

    switch (action) {
    case ACTION_END:

        if (!ignoreList.contains(rap.procInfo.processName) && !rap.sys) {
            ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);

            String self = ctx.getPackageName();

            if (self.equals(rap.procInfo.processName)) {
                Util.killSelf(handler, ctx, am, self);
            } else {
                endProcess(am, rap.procInfo.pkgList, self);

                handler.removeCallbacks(task);
                handler.post(task);
            }
        }

        break;
    case ACTION_END_OTHERS:

        endAllExcept(rap.procInfo.processName);

        break;
    case ACTION_SWITCH:

        String pkgName = rap.procInfo.processName;

        if (!pkgName.equals(ctx.getPackageName())) {
            Intent it = new Intent("android.intent.action.MAIN"); //$NON-NLS-1$
            it.addCategory(Intent.CATEGORY_LAUNCHER);

            List<ResolveInfo> acts = ctx.getPackageManager().queryIntentActivities(it, 0);

            if (acts != null) {
                boolean started = false;

                for (int i = 0, size = acts.size(); i < size; i++) {
                    ResolveInfo ri = acts.get(i);

                    if (pkgName.equals(ri.activityInfo.packageName)) {
                        it.setClassName(ri.activityInfo.packageName, ri.activityInfo.name);

                        it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                                .addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);

                        try {
                            startActivity(it);

                            started = true;
                        } catch (Exception e) {
                            Log.e(ProcessManager.class.getName(), "Cannot start activity: " + pkgName, //$NON-NLS-1$
                                    e);
                        }

                        break;
                    }
                }

                if (!started) {
                    Util.shortToast(ctx, R.string.error_switch_task);
                }
            }
        }

        break;
    case ACTION_IGNORE:

        if (!ignoreList.contains(rap.procInfo.processName) && !rap.sys) {
            ignoreList.add(rap.procInfo.processName);

            setIgnoreList(ignoreList);

            if (IGNORE_ACTION_HIDDEN == Util.getIntOption(ctx, PSTORE_PROCESSMANAGER, PREF_KEY_IGNORE_ACTION,
                    IGNORE_ACTION_HIDDEN)) {
                handler.removeCallbacks(task);
                handler.post(task);
            }
        }

        break;
    case ACTION_DETAILS:

        String[] status = readProcStatus(rap.procInfo.pid);

        StringBuffer sb = new StringBuffer().append("<small>") //$NON-NLS-1$
                .append(getString(R.string.proc_name)).append(": ") //$NON-NLS-1$
                .append(rap.procInfo.processName).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.pid)).append(": ") //$NON-NLS-1$
                .append(rap.procInfo.pid).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.uid)).append(": ") //$NON-NLS-1$
                .append(status == null ? "" : status[1]) //$NON-NLS-1$
                .append("<br>") //$NON-NLS-1$
                .append(getString(R.string.gid)).append(": ") //$NON-NLS-1$
                .append(status == null ? "" : status[2]) //$NON-NLS-1$
                .append("<br>") //$NON-NLS-1$
                .append(getString(R.string.state)).append(": ") //$NON-NLS-1$
                .append(status == null ? "" : status[0]) //$NON-NLS-1$
                .append("<br>") //$NON-NLS-1$
                .append(getString(R.string.threads)).append(": ") //$NON-NLS-1$
                .append(status == null ? "" : status[3]) //$NON-NLS-1$
                .append("<br>") //$NON-NLS-1$
                .append(getString(R.string.importance)).append(": ") //$NON-NLS-1$
                .append(rap.procInfo.importance).append("<br>LRU: ") //$NON-NLS-1$
                .append(rap.procInfo.lru).append("<br>") //$NON-NLS-1$
                .append(getString(R.string.pkg_name)).append(": "); //$NON-NLS-1$

        if (rap.procInfo.pkgList != null) {
            int i = 0;

            for (String pkg : rap.procInfo.pkgList) {
                if (pkg != null) {
                    if (i > 0) {
                        sb.append(", "); //$NON-NLS-1$
                    }
                    sb.append(pkg);
                    i++;
                }
            }
        }

        sb.append("</small>"); //$NON-NLS-1$

        new AlertDialog.Builder(ctx).setTitle(rap.label == null ? rap.procInfo.processName : rap.label)
                .setNeutralButton(R.string.close, null).setMessage(Html.fromHtml(sb.toString())).create()
                .show();

        break;
    case ACTION_MENU:

        final boolean protect = ignoreList.contains(rap.procInfo.processName) || rap.sys;

        OnClickListener listener = new OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

                // bypass the 'showMenu' action offset
                int action = which + 1;

                if (!protect || (action != ACTION_END && action != ACTION_IGNORE)) {
                    handleAction(rap, action);
                }
            }
        };

        new AlertDialog.Builder(
                ctx).setTitle(R.string.actions)
                        .setItems(
                                new CharSequence[] { getString(R.string.switch_to),
                                        protect ? Html.fromHtml("<font color=\"#848484\">" //$NON-NLS-1$
                                                + getString(R.string.end_task) + "</font>") //$NON-NLS-1$
                                                : getString(R.string.end_task),
                                        getString(R.string.end_others),
                                        protect ? Html.fromHtml("<font color=\"#848484\">" //$NON-NLS-1$
                                                + getString(R.string.ignore) + "</font>") //$NON-NLS-1$
                                                : getString(R.string.ignore),
                                        getString(R.string.details) },
                                listener)
                        .create().show();

        break;
    }
}

From source file:net.wequick.small.ApkBundleLauncher.java

@Override
public void setUp(Context context) {
    super.setUp(context);

    Field f;//from  w ww . j  av  a2s .c o  m

    // AOP for pending intent
    try {
        f = TaskStackBuilder.class.getDeclaredField("IMPL");
        f.setAccessible(true);
        final Object impl = f.get(TaskStackBuilder.class);
        InvocationHandler aop = new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                Intent[] intents = (Intent[]) args[1];
                for (Intent intent : intents) {
                    sBundleInstrumentation.wrapIntent(intent);
                    intent.setAction(Intent.ACTION_MAIN);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                }
                return method.invoke(impl, args);
            }
        };
        Object newImpl = Proxy.newProxyInstance(context.getClassLoader(), impl.getClass().getInterfaces(), aop);
        f.set(TaskStackBuilder.class, newImpl);
    } catch (Exception ignored) {
        ignored.printStackTrace();
    }
}

From source file:com.yamin.kk.service.AudioService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void showNotification() {
    try {/*  w  ww .j a va2  s. c o m*/
        Bitmap cover = AudioUtil.getCover(this, getCurrentMedia(), 64);
        String title = getCurrentMedia().getTitle();
        String artist = getCurrentMedia().getArtist();
        String album = getCurrentMedia().getAlbum();
        Notification notification;

        // add notification to status bar
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_vlc).setTicker(title + " - " + artist).setAutoCancel(false)
                .setOngoing(true);

        Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(MainActivity.ACTION_SHOW_PLAYER);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        notificationIntent.putExtra(START_FROM_NOTIFICATION, true);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        if (Util.isJellyBeanOrLater()) {
            Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD);
            Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE);
            Intent iForward = new Intent(ACTION_REMOTE_FORWARD);
            Intent iStop = new Intent(ACTION_REMOTE_STOP);
            PendingIntent piBackward = PendingIntent.getBroadcast(this, 0, iBackward,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, iPlay,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piForward = PendingIntent.getBroadcast(this, 0, iForward,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piStop = PendingIntent.getBroadcast(this, 0, iStop,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification);
            if (cover != null)
                view.setImageViewBitmap(R.id.cover, cover);
            view.setTextViewText(R.id.songName, title);
            view.setTextViewText(R.id.artist, artist);
            view.setImageViewResource(R.id.play_pause,
                    mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play);
            view.setOnClickPendingIntent(R.id.play_pause, piPlay);
            view.setOnClickPendingIntent(R.id.forward, piForward);
            view.setOnClickPendingIntent(R.id.stop, piStop);
            view.setOnClickPendingIntent(R.id.content, pendingIntent);

            RemoteViews view_expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded);
            if (cover != null)
                view_expanded.setImageViewBitmap(R.id.cover, cover);
            view_expanded.setTextViewText(R.id.songName, title);
            view_expanded.setTextViewText(R.id.artist, artist);
            view_expanded.setTextViewText(R.id.album, album);
            view_expanded.setImageViewResource(R.id.play_pause,
                    mLibVLC.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play);
            view_expanded.setOnClickPendingIntent(R.id.backward, piBackward);
            view_expanded.setOnClickPendingIntent(R.id.play_pause, piPlay);
            view_expanded.setOnClickPendingIntent(R.id.forward, piForward);
            view_expanded.setOnClickPendingIntent(R.id.stop, piStop);
            view_expanded.setOnClickPendingIntent(R.id.content, pendingIntent);

            notification = builder.build();
            notification.contentView = view;
            notification.bigContentView = view_expanded;
        } else {
            builder.setLargeIcon(cover).setContentTitle(title)
                    .setContentText(Util.isJellyBeanOrLater() ? artist : getCurrentMedia().getSubtitle())
                    .setContentInfo(album).setContentIntent(pendingIntent);
            notification = builder.build();
        }

        startService(new Intent(this, AudioService.class));
        startForeground(3, notification);
    } catch (NoSuchMethodError e) {
        // Compat library is wrong on 3.2
        // http://code.google.com/p/android/issues/detail?id=36359
        // http://code.google.com/p/android/issues/detail?id=36502
    }
}

From source file:com.example.alyshia.customsimplelauncher.MainActivity.java

private void initUI() {

    mSpaceFrag.add(new AppsGridFragment());
    mSpaceFrag.add(new AppsGridFragment());

    mPagerAdapter = new workSpacePagerAdapter(getSupportFragmentManager());
    workSpaces.setAdapter(mPagerAdapter);

    Intent intent_ = new Intent(Intent.ACTION_MAIN, null);
    intent_.addCategory(Intent.CATEGORY_LAUNCHER);
    mPM = getPackageManager();/*from w  ww  .  j av a  2 s.com*/
    apps = mPM.queryIntentActivities(intent_, 0);
    apps_package = new ArrayList<>();
    optionalApps = new ArrayList<>();
    knoxappPrefs = getSharedPreferences(KnoxConstants.PREFS_KNOX, MODE_PRIVATE);
    knoxappPrefsEditor = knoxappPrefs.edit();

}

From source file:com.linkbubble.util.Util.java

public static List<ResolveInfo> getLauncherAppForApplicationIds(Context context, String applicationId) {
    Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
            .setPackage(applicationId);/*from   w  w  w.j a  v a  2 s .c o  m*/
    List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(intent, 0);
    if (resolveInfos != null && resolveInfos.size() > 0) {
        return resolveInfos;
    }
    return null;
}

From source file:com.allwinner.theatreplayer.launcher.activity.LaunchActivity.java

@Override
public void onClick(View view) {
    CellInfo cellInfo = (CellInfo) view.getTag();

    //      Log.i("jim", "1111111111111=======cellInfo.packageName = "+cellInfo.packageName);

    if (cellInfo != null && mLauncherModel != null) {
        //         Log.i("jim", "22222222222=======cellInfo.packageName = "+cellInfo.packageName);
        if (cellInfo.packageName.equals(Constants.PACKAGE_QQ)
                && SharedPreUtil.isFirstRunQQ(Constants.PACKAGE_QQ)) {
            LauncherApp.gIsFirstRunQQ = true;
            SharedPreUtil.saveQQVersionNum(Constants.PACKAGE_QQ);
            if (!OrientatorService.mIsClose) {
                OrientatorService.closeOrientatorMode();
            }/*  www  . j a va  2  s .c o  m*/
        } else if (cellInfo.portrait.equals("true")) {
            if (LoadApplicationInfo.isInstalled(this, cellInfo.packageName)) {
                if (!OrientatorService.mIsClose) {
                    OrientatorService.closeOrientatorMode();
                }
            }

        } else {
            if (OrientatorService.mIsClose) {
                OrientatorService.forceLandscapeMode();
            }
        }
        //         Log.i("jim", "3333333=======cellInfo.packageName = "+cellInfo.packageName);
        if (cellInfo.packageName.equals(Constants.PACKAGE_VODTYPE)) {
            mLauncherModel.startVstByType(cellInfo.className, Constants.PACKAGE_VODTYPE);
            //            Log.i("jim", "4444444444444=======cellInfo.packageName = "+cellInfo.packageName);

        } else if (cellInfo.packageName.equals(Constants.PACKAGE_VST_RECORD)
                || cellInfo.packageName.equals(Constants.PACKAGE_VST_SETTING)) {
            mLauncherModel.startActivityByAction(cellInfo.packageName);
            //            Log.i("jim", "5555555555=======cellInfo.packageName = "+cellInfo.packageName);
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_GALLERY)) {
            if (cellInfo.className.equals(Constants.PACKAGE_CAMERA)) {
                //               Log.i("jim", "66666666666=======cellInfo.packageName = "+cellInfo.packageName);
                try {
                    ComponentName componentName = new ComponentName(Constants.PACKAGE_GALLERY,
                            Constants.PACKAGE_CAMERA);
                    Intent intent = new Intent();
                    intent.setComponent(componentName);
                    startActivity(intent);
                } catch (Exception e) {
                    Toast.makeText(this, cellInfo.packageName + " not found", Toast.LENGTH_SHORT).show();
                }
            } else {
                mLauncherModel.startThirdApk(Constants.PACKAGE_GALLERY, cellInfo.className);
                //               Log.i("jim", "7777777777777777=======cellInfo.packageName = "+cellInfo.packageName);
            }

        } else if (cellInfo.packageName.equals(Constants.PACKAGE_OCOCCI_VIDEO)) {
            //            Log.i("jim", "AAAAAAAAAAAA=======cellInfo.packageName = "+cellInfo.packageName);
            //if(cellInfo.className.equals("tv")){               

            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            ComponentName cn = new ComponentName(Constants.PACKAGE_OCOCCI_VIDEO,
                    "com.ococci.video.activity.WelcomeActivity");
            intent.putExtra("video_request_flag", cellInfo.className);
            intent.setComponent(cn);
            startActivity(intent);

            //}
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_HEALTH)) {
            Intent intent = new Intent();
            intent.setAction("com.vst.allwinner.intent.action.ChannelActivity");
            intent.putExtra("cid", cellInfo.className);//
            startActivity(intent);
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_CHILDREN)) {

            Intent intent = new Intent();
            intent.setAction("myvst.intent.action.children.list.v2");
            intent.putExtra("uuid", "424C4C7347456F6F1CF462");
            intent.putExtra("playerIndex", 1);
            startActivity(intent);
        } else if (cellInfo.className != null && !cellInfo.className.equals("")) {
            mLauncherModel.startActivity(cellInfo.packageName, cellInfo.className);

            //            Log.i("jim", "88888888888=======cellInfo.packageName = "+cellInfo.packageName);
        } else if (cellInfo.packageName.equals(Constants.PACKAGE_LIVE)) {
            //            Log.i("jim", "999999999999999=======cellInfo.packageName = "+cellInfo.packageName);
            if (mLiveAppAuthorized) {
                mLauncherModel.startThirdApk(cellInfo.packageName);
            } else {
                CustomToast.showToast(this, R.string.live_unauthorized);
            }
        } else if (cellInfo.packageName.equals("com.allwinner.theatreplayer.launcher.AllAppActivity")) {
            //             Log.i("Trim", cellInfo.packageName);

            Intent intent = new Intent(LaunchActivity.this, LocalAppActivity.class);
            startActivity(intent);
        } else if (cellInfo.packageName.equals("com.android.settings")) {
            //R16settings
            if (Utils.isPkgInstalled(LaunchActivity.this, Constants.PACKAGE_SETTINGS)) {
                mLauncherModel.startThirdApk(Constants.PACKAGE_SETTINGS);
            } else {
                mLauncherModel.startThirdApk(cellInfo.packageName);
            }
        } else {
            //            Log.i("Trim", cellInfo.packageName);
            mLauncherModel.startThirdApk(cellInfo.packageName);
        }
    }
}

From source file:dk.nota.lyt.libvlc.PlaybackService.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void showNotification() {
    PendingIntent piStop = PendingIntent.getBroadcast(this, REQ_CODE, new Intent(ACTION_REMOTE_STOP),
            PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent piBackward = PendingIntent.getBroadcast(this, REQ_CODE, new Intent(ACTION_REMOTE_BACKWARD),
            PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent piPlay = PendingIntent.getBroadcast(this, REQ_CODE, new Intent(ACTION_REMOTE_PLAYPAUSE),
            PendingIntent.FLAG_UPDATE_CURRENT);
    PendingIntent piForward = PendingIntent.getBroadcast(this, REQ_CODE, new Intent(ACTION_REMOTE_FORWARD),
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder bob = new NotificationCompat.Builder(this);
    bob.addAction(R.drawable.ic_skip_previous_white_24dp, getText(R.string.previous), piBackward);
    if (mMediaPlayer.isPlaying()) {
        bob.addAction(R.drawable.ic_pause_white_24dp, getText(R.string.pause), piPlay);
    } else {/*  w  w  w  . java2s  .c  om*/
        bob.addAction(R.drawable.ic_play_arrow_white_24dp, this.getText(R.string.play), piPlay);
    }
    bob.addAction(R.drawable.ic_skip_next_white_24dp, getText(R.string.next), piForward);

    boolean isPlaying = mMediaPlayer.isPlaying();
    long playbackPosition = mMediaPlayer.getTime();
    MediaWrapper currentMedia = getCurrentMedia();

    Log.d(TAG, "Playback position: " + playbackPosition);

    bob.setStyle(new NotificationCompat.MediaStyle().setMediaSession(mMediaSession.getSessionToken())
            .setShowActionsInCompactView(1).setShowCancelButton(true).setCancelButtonIntent(piStop))
            .setSmallIcon(R.drawable.ic_notification).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setContentTitle(currentMedia.getTitle())
            .setContentText(currentMedia.getArtist() + " - " + currentMedia.getAlbum())
            .setTicker(currentMedia.getTitle()) //TODO: used by accessibility services!
            .setShowWhen(false).setDeleteIntent(piStop);

    if (mNotificationActivity != null) {
        Intent onClickIntent = new Intent(this, mNotificationActivity.getClass());
        onClickIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        onClickIntent.setAction(mNotificationAction);
        onClickIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        PendingIntent piOnClick = PendingIntent.getActivity(this, REQ_CODE, onClickIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        bob.setContentIntent(piOnClick);
    }

    if (currentMedia.isPictureParsed()) {
        bob.setLargeIcon(currentMedia.getPicture());
    } else if (currentMedia.getArtworkURL() != null) {
        loadArtworkFromUrlAsync(currentMedia.getArtworkURL(), bob);
    } else {
        bob.setLargeIcon(getDefaultArtwork());
    }

    Notification notification = bob.build();
    if (!AndroidUtil.isLolliPopOrLater() || isPlaying) {
        startForeground(NOTIFICATION_ID, notification);
    } else {
        stopForeground(false);
        NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, notification);
    }
}

From source file:uk.co.droidinactu.ebooklauncher.EBookLauncherActivity.java

private void updateButtonCounts() {
    new Thread() {
        @Override/*w  ww  .  j a va  2  s  .c  o  m*/
        public void run() {
            setName("updateButtonCounts()");
            Cursor tmpCursor = myApp.dataMdl.getBooks(EBookLauncherActivity.this.getApplication(), "",
                    BookSortBy.TITLE, "");
            if (tmpCursor != null) {
                btnBooksCount = tmpCursor.getCount();
                tmpCursor.close();
            }
            tmpCursor = myApp.dataMdl.getCollections(0, 999, null);
            if (tmpCursor != null) {
                btnCollectionsCount = tmpCursor.getCount();
                tmpCursor.close();
            }
            tmpCursor = myApp.dataMdl.getPeriodicals(EBookLauncherActivity.this.getApplication());
            if (tmpCursor != null) {
                btnPeriodicalsCount = tmpCursor.getCount();
                tmpCursor.close();
            }

            final PackageManager manager = EBookLauncherActivity.this.getPackageManager();
            final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
            final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);

            EBookLauncherActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    btnApps.setText(String.format(
                            EBookLauncherActivity.this.getResources().getString(R.string.page1_Apps),
                            apps.size()));
                    btnBooks.setText(String.format(
                            EBookLauncherActivity.this.getResources().getString(R.string.page1_Books),
                            btnBooksCount));
                    btnCollections.setText(String.format(
                            EBookLauncherActivity.this.getResources().getString(R.string.page1_Collections),
                            btnCollectionsCount));
                    btnPeriodicals.setText(String.format(
                            EBookLauncherActivity.this.getResources().getString(R.string.page1_Periodicals),
                            btnPeriodicalsCount));
                }
            });
        }
    }.start();
}

From source file:org.videolan.vlc.audio.AudioService.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void showNotification() {
    try {/*  w  w  w . ja  v  a  2 s  .c  o m*/
        Media media = getCurrentMedia();
        if (media == null)
            return;
        Bitmap cover = AudioUtil.getCover(this, media, 64);
        String title = media.getTitle();
        String artist = media.getArtist();
        String album = media.getAlbum();
        Notification notification;

        // add notification to status bar
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_vlc).setTicker(title + " - " + artist).setAutoCancel(false)
                .setOngoing(true);

        Intent notificationIntent = new Intent(this, MainActivity.class);
        notificationIntent.setAction(MainActivity.ACTION_SHOW_PLAYER);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        notificationIntent.putExtra(START_FROM_NOTIFICATION, true);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        if (LibVlcUtil.isJellyBeanOrLater()) {
            Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD);
            Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE);
            Intent iForward = new Intent(ACTION_REMOTE_FORWARD);
            Intent iStop = new Intent(ACTION_REMOTE_STOP);
            PendingIntent piBackward = PendingIntent.getBroadcast(this, 0, iBackward,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, iPlay,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piForward = PendingIntent.getBroadcast(this, 0, iForward,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piStop = PendingIntent.getBroadcast(this, 0, iStop,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification);
            if (cover != null)
                view.setImageViewBitmap(R.id.cover, cover);
            view.setTextViewText(R.id.songName, title);
            view.setTextViewText(R.id.artist, artist);
            view.setImageViewResource(R.id.play_pause,
                    mLibVLC.isPlaying() ? R.drawable.ic_pause_w : R.drawable.ic_play_w);
            view.setOnClickPendingIntent(R.id.play_pause, piPlay);
            view.setOnClickPendingIntent(R.id.forward, piForward);
            view.setOnClickPendingIntent(R.id.stop, piStop);
            view.setOnClickPendingIntent(R.id.content, pendingIntent);

            RemoteViews view_expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded);
            if (cover != null)
                view_expanded.setImageViewBitmap(R.id.cover, cover);
            view_expanded.setTextViewText(R.id.songName, title);
            view_expanded.setTextViewText(R.id.artist, artist);
            view_expanded.setTextViewText(R.id.album, album);
            view_expanded.setImageViewResource(R.id.play_pause,
                    mLibVLC.isPlaying() ? R.drawable.ic_pause_w : R.drawable.ic_play_w);
            view_expanded.setOnClickPendingIntent(R.id.backward, piBackward);
            view_expanded.setOnClickPendingIntent(R.id.play_pause, piPlay);
            view_expanded.setOnClickPendingIntent(R.id.forward, piForward);
            view_expanded.setOnClickPendingIntent(R.id.stop, piStop);
            view_expanded.setOnClickPendingIntent(R.id.content, pendingIntent);

            notification = builder.build();
            notification.contentView = view;
            notification.bigContentView = view_expanded;
        } else {
            builder.setLargeIcon(cover).setContentTitle(title)
                    .setContentText(LibVlcUtil.isJellyBeanOrLater() ? artist : media.getSubtitle())
                    .setContentInfo(album).setContentIntent(pendingIntent);
            notification = builder.build();
        }

        startService(new Intent(this, AudioService.class));
        startForeground(3, notification);
    } catch (NoSuchMethodError e) {
        // Compat library is wrong on 3.2
        // http://code.google.com/p/android/issues/detail?id=36359
        // http://code.google.com/p/android/issues/detail?id=36502
    }
}

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

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void showNotification() {
    Constant.print_i("AudioService----------->showNotification");
    try {/*from  w  w  w  .j  a  v  a  2  s .c o m*/
        Media media = getCurrentMedia();
        if (media == null)
            return;
        Bitmap cover = AudioUtil.getCover(this, media, 64);
        String title = media.getTitle();
        String artist = media.getArtist();
        String album = media.getAlbum();
        Notification notification;

        // add notification to status bar
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.icon_music).setTicker(title + " - " + artist).setAutoCancel(false)
                .setOngoing(true);

        //Activity
        Intent notificationIntent = new Intent(this, MusicPlayActivity.class);
        notificationIntent.setAction(MusicPlayActivity.ACTION_SHOW_PLAYER);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        notificationIntent.putExtra(START_FROM_NOTIFICATION, true);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        if (LibVlcUtil.isJellyBeanOrLater()) {
            Intent iBackward = new Intent(ACTION_REMOTE_BACKWARD);
            Intent iPlay = new Intent(ACTION_REMOTE_PLAYPAUSE);
            Intent iForward = new Intent(ACTION_REMOTE_FORWARD);
            Intent iStop = new Intent(ACTION_REMOTE_STOP);
            PendingIntent piBackward = PendingIntent.getBroadcast(this, 0, iBackward,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piPlay = PendingIntent.getBroadcast(this, 0, iPlay,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piForward = PendingIntent.getBroadcast(this, 0, iForward,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent piStop = PendingIntent.getBroadcast(this, 0, iStop,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            RemoteViews view = new RemoteViews(getPackageName(), R.layout.notification);
            if (cover != null)
                view.setImageViewBitmap(R.id.cover, cover);
            view.setTextViewText(R.id.songName, title);
            view.setTextViewText(R.id.artist, artist);
            view.setImageViewResource(R.id.play_pause,
                    mLibVLC.isPlaying() ? R.drawable.ic_pause_w : R.drawable.ic_play_w);
            view.setOnClickPendingIntent(R.id.play_pause, piPlay);
            view.setOnClickPendingIntent(R.id.forward, piForward);
            view.setOnClickPendingIntent(R.id.stop, piStop);
            view.setOnClickPendingIntent(R.id.content, pendingIntent);

            RemoteViews view_expanded = new RemoteViews(getPackageName(), R.layout.notification_expanded);
            if (cover != null)
                view_expanded.setImageViewBitmap(R.id.cover, cover);
            view_expanded.setTextViewText(R.id.songName, title);
            view_expanded.setTextViewText(R.id.artist, artist);
            view_expanded.setTextViewText(R.id.album, album);
            view_expanded.setImageViewResource(R.id.play_pause,
                    mLibVLC.isPlaying() ? R.drawable.ic_pause_w : R.drawable.ic_play_w);
            view_expanded.setOnClickPendingIntent(R.id.backward, piBackward);
            view_expanded.setOnClickPendingIntent(R.id.play_pause, piPlay);
            view_expanded.setOnClickPendingIntent(R.id.forward, piForward);
            view_expanded.setOnClickPendingIntent(R.id.stop, piStop);
            view_expanded.setOnClickPendingIntent(R.id.content, pendingIntent);

            notification = builder.build();
            notification.contentView = view;
            notification.bigContentView = view_expanded;
        } else {
            builder.setLargeIcon(cover).setContentTitle(title)
                    .setContentText(LibVlcUtil.isJellyBeanOrLater() ? artist : media.getSubtitle())
                    .setContentInfo(album).setContentIntent(pendingIntent);
            notification = builder.build();
        }

        startService(new Intent(this, AudioService.class));
        startForeground(3, notification);
    } catch (NoSuchMethodError e) {
        // Compat library is wrong on 3.2
        // http://code.google.com/p/android/issues/detail?id=36359
        // http://code.google.com/p/android/issues/detail?id=36502
    }
    Constant.print_i("AudioService----------->showNotification----end");
}