Example usage for android.graphics BitmapFactory decodeResource

List of usage examples for android.graphics BitmapFactory decodeResource

Introduction

In this page you can find the example usage for android.graphics BitmapFactory decodeResource.

Prototype

public static Bitmap decodeResource(Resources res, int id) 

Source Link

Document

Synonym for #decodeResource(Resources,int,android.graphics.BitmapFactory.Options) with null Options.

Usage

From source file:name.gumartinm.weather.information.fragment.overview.OverviewFragment.java

private void updateUI(final Forecast forecastWeatherData) {

    // 1. Update units of measurement.
    final UnitsConversor tempUnitsConversor = new TempUnitsConversor(
            this.getActivity().getApplicationContext());

    // 2. Update number day forecast.
    final SharedPreferences sharedPreferences = PreferenceManager
            .getDefaultSharedPreferences(this.getActivity().getApplicationContext());
    final String keyPreference = this.getResources().getString(R.string.weather_preferences_day_forecast_key);
    final String dayForecast = sharedPreferences.getString(keyPreference, "5");
    final int mDayForecast = Integer.valueOf(dayForecast);

    // 3. Formatters
    final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US);
    tempFormatter.applyPattern("###.##");
    final SimpleDateFormat dayNameFormatter = new SimpleDateFormat("EEE", Locale.US);
    final SimpleDateFormat monthAndDayNumberormatter = new SimpleDateFormat("MMM d", Locale.US);

    // 4. Prepare data for UI.
    final List<OverviewEntry> entries = new ArrayList<OverviewEntry>();
    final OverviewAdapter adapter = new OverviewAdapter(this.getActivity(), R.layout.weather_main_entry_list);
    final Calendar calendar = Calendar.getInstance();
    int count = mDayForecast;
    for (final name.gumartinm.weather.information.model.forecastweather.List forecast : forecastWeatherData
            .getList()) {/*from   www .  j a  v a2s.c  o  m*/

        Bitmap picture;

        if ((forecast.getWeather().size() > 0) && (forecast.getWeather().get(0).getIcon() != null)
                && (IconsList.getIcon(forecast.getWeather().get(0).getIcon()) != null)) {
            final String icon = forecast.getWeather().get(0).getIcon();
            picture = BitmapFactory.decodeResource(this.getResources(),
                    IconsList.getIcon(icon).getResourceDrawable());
        } else {
            picture = BitmapFactory.decodeResource(this.getResources(), R.drawable.weather_severe_alert);
        }

        final Long forecastUNIXDate = (Long) forecast.getDt();
        calendar.setTimeInMillis(forecastUNIXDate * 1000L);
        final Date dayTime = calendar.getTime();
        final String dayTextName = dayNameFormatter.format(dayTime);
        final String monthAndDayNumberText = monthAndDayNumberormatter.format(dayTime);

        Double maxTemp = null;
        if (forecast.getTemp().getMax() != null) {
            maxTemp = (Double) forecast.getTemp().getMax();
            maxTemp = tempUnitsConversor.doConversion(maxTemp);
        }

        Double minTemp = null;
        if (forecast.getTemp().getMin() != null) {
            minTemp = (Double) forecast.getTemp().getMin();
            minTemp = tempUnitsConversor.doConversion(minTemp);
        }

        if ((maxTemp != null) && (minTemp != null)) {
            // TODO i18n?
            final String tempSymbol = tempUnitsConversor.getSymbol();
            entries.add(new OverviewEntry(dayTextName, monthAndDayNumberText,
                    tempFormatter.format(maxTemp) + tempSymbol, tempFormatter.format(minTemp) + tempSymbol,
                    picture));
        }

        count = count - 1;
        if (count == 0) {
            break;
        }
    }

    // 5. Update UI.
    adapter.addAll(entries);
    this.setListAdapter(adapter);
}

From source file:com.actionbarsherlock.sample.hcgallery.MainActivity.java

void showNotification(boolean custom) {
    final Resources res = getResources();
    final NotificationManager notificationManager = (NotificationManager) getSystemService(
            NOTIFICATION_SERVICE);/*from   w ww.  j  ava 2s . c om*/

    Notification.Builder builder = new Notification.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_notify_example).setAutoCancel(true)
            .setTicker(getString(R.string.notification_text))
            .setContentIntent(getDialogPendingIntent("Tapped the notification entry."));

    if (custom) {
        // Sets a custom content view for the notification, including an image button.
        RemoteViews layout = new RemoteViews(getPackageName(), R.layout.notification);
        layout.setTextViewText(R.id.notification_title, getString(R.string.app_name));
        layout.setOnClickPendingIntent(R.id.notification_button,
                getDialogPendingIntent("Tapped the 'dialog' button in the notification."));
        builder.setContent(layout);

        // Notifications in Android 3.0 now have a standard mechanism for displaying large
        // bitmaps such as contact avatars. Here, we load an example image and resize it to the
        // appropriate size for large bitmaps in notifications.
        Bitmap largeIconTemp = BitmapFactory.decodeResource(res, R.drawable.notification_default_largeicon);
        Bitmap largeIcon = Bitmap.createScaledBitmap(largeIconTemp,
                res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width),
                res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height), false);
        largeIconTemp.recycle();

        builder.setLargeIcon(largeIcon);

    } else {
        builder.setNumber(7) // An example number.
                .setContentTitle(getString(R.string.app_name))
                .setContentText(getString(R.string.notification_text));
    }

    notificationManager.notify(NOTIFICATION_DEFAULT, builder.getNotification());
}

From source file:com.donnyfishball.fourzero.FourZeroActivity.java

private void postPhoto() {
    Bitmap image = BitmapFactory.decodeResource(this.getResources(), R.drawable.icon);
    SharePhoto sharePhoto = new SharePhoto.Builder().setBitmap(image).build();
    ArrayList<SharePhoto> photos = new ArrayList<>();
    photos.add(sharePhoto);/*  ww w.  j  a  v a  2s  . c  o  m*/

    SharePhotoContent sharePhotoContent = new SharePhotoContent.Builder().setPhotos(photos).build();
    if (canPresentShareDialogWithPhotos) {
        shareDialog.show(sharePhotoContent);
    } else if (hasPublishPermission()) {
        ShareApi.share(sharePhotoContent, shareCallback);
    } else {
        pendingAction = PendingAction.POST_PHOTO;
    }
}

From source file:com.classiqo.nativeandroid_32bitz.MediaNotificationManager.java

private Notification createNotification() {
    LogHelper.d(TAG, "updateNotificationMetadata.mMetadata = " + mMetadata);

    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }/*from  w  ww. j ava  2  s.c  om*/

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
    int playPauseButtonPosition = 0;

    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp,
                mService.getString(R.string.label_previous), mPreviousIntent);

        playPauseButtonPosition = 1;
    }

    addPlayPauseAction(notificationBuilder);

    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp,
                mService.getString(R.string.label_next), mNextIntent);
    }

    MediaDescriptionCompat description = mMetadata.getDescription();

    String fetchArtUrl = null;
    Bitmap art = null;

    if (description.getIconUri() != null) {
        String artUrl = description.getIconUri().toString();
        art = AlbumArtCache.getInstance().getBigImage(artUrl);

        if (art == null) {
            fetchArtUrl = artUrl;
            art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art);
        }
    }

    notificationBuilder
            .setStyle(new NotificationCompat.MediaStyle()
                    .setShowActionsInCompactView(new int[] { playPauseButtonPosition })
                    .setMediaSession(mSessionToken))
            .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setUsesChronometer(true)
            .setContentIntent(createContentIntent(description)).setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle()).setLargeIcon(art);

    if (mController != null && mController.getExtras() != null) {
        String castName = mController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);

        if (castName != null) {
            String castInfo = mService.getResources().getString(R.string.casting_to_device, castName);
            notificationBuilder.setSubText(castInfo);
            notificationBuilder.addAction(R.drawable.ic_close_black_24dp,
                    mService.getString(R.string.stop_casting), mStopCastIntent);
        }
    }

    setNotificationPlaybackState(notificationBuilder);

    if (fetchArtUrl != null) {
        fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder);
    }

    return notificationBuilder.build();
}

From source file:com.ayogo.cordova.notification.ScheduledNotificationManager.java

public void showNotification(ScheduledNotification scheduledNotification) {
    LOG.v(NotificationPlugin.TAG, "showNotification: " + scheduledNotification.toString());

    NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

    // Build the notification options
    builder.setDefaults(Notification.DEFAULT_ALL).setTicker(scheduledNotification.body)
            .setPriority(Notification.PRIORITY_HIGH).setAutoCancel(true);

    // TODO: add sound support
    // if (scheduledNotification.sound != null) {
    //     builder.setSound(sound);
    // }//w w  w  .j  a  v a2 s. c om

    if (scheduledNotification.body != null) {
        builder.setContentTitle(scheduledNotification.title);
        builder.setContentText(scheduledNotification.body);
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.body));
    } else {
        //Default the title to the app name
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);

            String appName = applicationInfo.loadLabel(pm).toString();

            builder.setContentTitle(appName);
            builder.setContentText(scheduledNotification.title);
            builder.setStyle(new NotificationCompat.BigTextStyle().bigText(scheduledNotification.title));
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set title for notification!");
            return;
        }
    }

    if (scheduledNotification.badge != null) {
        LOG.v(NotificationPlugin.TAG, "showNotification: has a badge!");
        builder.setSmallIcon(getResIdForDrawable(scheduledNotification.badge));
    } else {
        LOG.v(NotificationPlugin.TAG, "showNotification: has no badge, use app icon!");
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);
            Resources resources = pm.getResourcesForApplication(applicationInfo);
            builder.setSmallIcon(applicationInfo.icon);
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set badge for notification!");
            return;
        }
    }

    if (scheduledNotification.icon != null) {
        LOG.v(NotificationPlugin.TAG, "showNotification: has an icon!");
        builder.setLargeIcon(getIconFromUri(scheduledNotification.icon));
    } else {
        LOG.v(NotificationPlugin.TAG, "showNotification: has no icon, use app icon!");
        try {
            PackageManager pm = context.getPackageManager();
            ApplicationInfo applicationInfo = pm.getApplicationInfo(context.getPackageName(),
                    PackageManager.GET_META_DATA);
            Resources resources = pm.getResourcesForApplication(applicationInfo);
            Bitmap appIconBitmap = BitmapFactory.decodeResource(resources, applicationInfo.icon);
            builder.setLargeIcon(appIconBitmap);
        } catch (NameNotFoundException e) {
            LOG.v(NotificationPlugin.TAG, "Failed to set icon for notification!");
            return;
        }
    }

    Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    launchIntent.setAction("notification");

    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launchIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(contentIntent);

    Notification notification = builder.build();

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    LOG.v(NotificationPlugin.TAG, "notify!");
    notificationManager.notify(scheduledNotification.tag.hashCode(), notification);
}

From source file:name.gumartinm.weather.information.widget.WidgetIntentService.java

private RemoteViews makeView(final Current current, final WeatherLocation weatherLocation,
        final int appWidgetId) {

    // 1. Update units of measurement.

    UnitsConversor tempUnitsConversor;//w w w  .  java2s .  c om
    String keyPreference = this.getApplicationContext()
            .getString(R.string.widget_preferences_temperature_units_key);
    String realKeyPreference = keyPreference + "_" + appWidgetId;
    // What was saved to permanent storage (or default values if it is the first time)
    final int tempValue = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE)
            .getInt(realKeyPreference, 0);
    final String tempSymbol = this.getResources()
            .getStringArray(R.array.weather_preferences_temperature)[tempValue];
    if (tempValue == 0) {
        tempUnitsConversor = new UnitsConversor() {

            @Override
            public double doConversion(final double value) {
                return value - 273.15;
            }

        };
    } else if (tempValue == 1) {
        tempUnitsConversor = new UnitsConversor() {

            @Override
            public double doConversion(final double value) {
                return (value * 1.8) - 459.67;
            }

        };
    } else {
        tempUnitsConversor = new UnitsConversor() {

            @Override
            public double doConversion(final double value) {
                return value;
            }

        };
    }

    // 2. Update country.
    keyPreference = this.getApplicationContext().getString(R.string.widget_preferences_country_switch_key);
    realKeyPreference = keyPreference + "_" + appWidgetId;
    // What was saved to permanent storage (or default values if it is the first time)
    final boolean isCountry = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE)
            .getBoolean(realKeyPreference, false);

    // 3. Formatters
    final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US);
    tempFormatter.applyPattern("###.##");

    // 4. Prepare data for RemoteViews.
    String tempMax = "";
    if (current.getMain().getTemp_max() != null) {
        double conversion = (Double) current.getMain().getTemp_max();
        conversion = tempUnitsConversor.doConversion(conversion);
        tempMax = tempFormatter.format(conversion) + tempSymbol;
    }
    String tempMin = "";
    if (current.getMain().getTemp_min() != null) {
        double conversion = (Double) current.getMain().getTemp_min();
        conversion = tempUnitsConversor.doConversion(conversion);
        tempMin = tempFormatter.format(conversion) + tempSymbol;
    }
    Bitmap picture;
    if ((current.getWeather().size() > 0) && (current.getWeather().get(0).getIcon() != null)
            && (IconsList.getIcon(current.getWeather().get(0).getIcon()) != null)) {
        final String icon = current.getWeather().get(0).getIcon();
        picture = BitmapFactory.decodeResource(this.getResources(),
                IconsList.getIcon(icon).getResourceDrawable());
    } else {
        picture = BitmapFactory.decodeResource(this.getResources(), R.drawable.weather_severe_alert);
    }
    final String city = weatherLocation.getCity();
    final String country = weatherLocation.getCountry();

    // 5. Insert data in RemoteViews.
    final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(),
            R.layout.appwidget);
    remoteView.setImageViewBitmap(R.id.weather_appwidget_image, picture);
    remoteView.setTextViewText(R.id.weather_appwidget_temperature_max, tempMax);
    remoteView.setTextViewText(R.id.weather_appwidget_temperature_min, tempMin);
    remoteView.setTextViewText(R.id.weather_appwidget_city, city);
    if (!isCountry) {
        remoteView.setViewVisibility(R.id.weather_appwidget_country, View.GONE);
    } else {
        // TODO: It is as if Android had a view cache. If I did not set VISIBLE value,
        // the country field would be gone forever... :/
        remoteView.setViewVisibility(R.id.weather_appwidget_country, View.VISIBLE);
        remoteView.setTextViewText(R.id.weather_appwidget_country, country);
    }

    // 6. Activity launcher.
    final Intent resultIntent = new Intent(this.getApplicationContext(), WidgetConfigure.class);
    resultIntent.putExtra("actionFromUser", true);
    resultIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    // From: http://stackoverflow.com/questions/4011178/multiple-instances-of-widget-only-updating-last-widget
    final Uri data = Uri.withAppendedPath(Uri.parse("PAIN" + "://widget/id/"), String.valueOf(appWidgetId));
    resultIntent.setData(data);

    final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext());
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(WidgetConfigure.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);
    remoteView.setOnClickPendingIntent(R.id.weather_appwidget, resultPendingIntent);

    return remoteView;
}

From source file:mobisocial.bento.anyshare.util.DBHelper.java

public long storeLinkobjInDatabase(DbObj obj, Context context) {
    long localId = -1; // if replace entry, set ID
    long hash = obj.getHash();
    Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_html);
    byte[] raw = BitmapHelper.bitmapToBytes(icon);

    String feedname = obj.getFeedName();
    long parentid = 0;
    try {/*from  w  ww  .ja v  a2s .  com*/
        if (obj.getJson().has("target_relation") && obj.getJson().getString("target_relation").equals("parent")
                && obj.getJson().has("target_hash")) {
            parentid = objIdForHash(obj.getJson().getLong("target_hash"));
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    DbUser usr = obj.getSender();
    String sender = "";
    if (usr != null) {
        sender = usr.getName();
    }

    long timestamp = 0;
    String title = "";
    try {
        timestamp = Long.parseLong(obj.getJson().getString("timestamp"));
        title = obj.getJson().getString("title");
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    // add object
    long objId = (localId == -1) ? getNextId() : localId;
    String desc = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT)
            .format(new Date(timestamp));
    if (!sender.isEmpty()) {
        desc += " by " + sender;
    }

    ContentValues cv = new ContentValues();
    cv.put(ItemObject._ID, objId);
    cv.put(ItemObject.FEEDNAME, feedname);
    cv.put(ItemObject.TITLE, title);
    cv.put(ItemObject.DESC, desc);
    cv.put(ItemObject.TIMESTAMP, timestamp);
    cv.put(ItemObject.OBJHASH, hash);
    cv.put(ItemObject.PARENT_ID, parentid);

    if (raw != null) {
        cv.put(ItemObject.RAW, raw);
    }

    long newObjId = getWritableDatabase().insertOrThrow(ItemObject.TABLE, null, cv);

    return objId;
}

From source file:com.teinproductions.tein.papyrosprogress.UpdateCheckReceiver.java

private static void issueBlogNotification(Context context) {
    String title = context.getString(R.string.notification_title);
    String message = context.getString(R.string.blog_notification_content);

    PendingIntent pendingIntent;/*w  ww . j  a  v  a  2 s  .c  om*/
    try {
        pendingIntent = PendingIntent.getActivity(context, 0,
                new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.PAPYROS_BLOG_URL)),
                PendingIntent.FLAG_UPDATE_CURRENT);
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(message).setContentIntent(pendingIntent)
            .setSmallIcon(R.mipmap.notification_small_icon)
            .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
            .setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true);
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(BLOG_NOTIFICATION_ID, builder.build());
}

From source file:com.bcp.bcp.geofencing.GeofenceTransitionsIntentService.java

/**
 * Posts a notification in the notification bar when a transition is detected.
 * If the user clicks the notification, control goes to the MainActivity.
 *///w w w.  ja  v  a2 s . c  om
private void sendNotification(String notificationDetails) {
    // Create an explicit content Intent that starts the main Activity.
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

    // Construct a task stack.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Add the main Activity to the task stack as the parent.
    stackBuilder.addParentStack(MainActivity.class);

    // Push the content Intent onto the stack.
    stackBuilder.addNextIntent(notificationIntent);

    // Get a PendingIntent containing the entire back stack.
    PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Get a notification builder that's compatible with platform versions >= 4
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Define the notification settings.
    builder.setSmallIcon(R.mipmap.ic_launcher)
            // In a real app, you may want to use a library like Volley
            // to decode the Bitmap.
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
            .setColor(Color.RED).setContentTitle(notificationDetails)
            .setContentText(getString(R.string.geofence_transition_notification_text))
            .setContentIntent(notificationPendingIntent);

    // Dismiss notification once the user touches it.
    builder.setAutoCancel(true);

    // Get an instance of the Notification manager
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    // Issue the notification
    mNotificationManager.notify(0, builder.build());
}

From source file:com.allthatseries.RNAudioPlayer.MediaNotificationManager.java

private Notification createNotification() {
    if (mMetadata == null || mPlaybackState == null) {
        return null;
    }//from   w w  w  .j a  va 2s  .c  o m

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
    int playPauseButtonPosition = 0;

    // If skip to previous action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp, "previous", mPreviousIntent);

        // If there is a "skip to previous" button, the play/pause button will
        // be the second one. We need to keep track of it, because the MediaStyle notification
        // requires to specify the index of the buttons (actions) that should be visible
        // when in compact view.
        playPauseButtonPosition = 1;
    }

    addPlayPauseAction(notificationBuilder);

    // If skip to next action is enabled
    if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
        notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp, "next", mNextIntent);
    }

    MediaDescriptionCompat description = mMetadata.getDescription();

    String fetchArtUrl = null;
    Bitmap art = null;
    if (description.getIconUri() != null) {
        // This sample assumes the iconUri will be a valid URL formatted String, but
        // it can actually be any valid Android Uri formatted String.
        // async fetch the album art icon
        String artUrl = description.getIconUri().toString();
        art = AlbumArtCache.getInstance().getBigImage(artUrl);
        if (art == null) {
            fetchArtUrl = artUrl;
            // use a placeholder art while the remote art is being downloaded
            art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art);
        }
    }

    // Basically we use notification icon but it doesn't exist we use launcher icon
    Context context = mService.getApplicationContext();
    int resId = context.getResources().getIdentifier("ic_notification", "drawable", context.getPackageName());
    if (resId == 0) {
        resId = context.getResources().getIdentifier("ic_launcher", "mipmap", context.getPackageName());
    }

    notificationBuilder
            .setStyle(new NotificationCompat.MediaStyle()
                    .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view
                    .setMediaSession(mSessionToken))
            .setColor(0xffdf533b).setSmallIcon(resId).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setUsesChronometer(true).setContentTitle(description.getTitle())
            .setContentText(description.getSubtitle()).setLargeIcon(art);

    setNotificationPlaybackState(notificationBuilder);

    // We should get MainActivity.class to set pendingIntent
    // If there exists better way, it should place this logic
    String packageName = mService.getApplicationContext().getPackageName();
    Intent launchIntent = mService.getApplicationContext().getPackageManager()
            .getLaunchIntentForPackage(packageName);
    String className = launchIntent.getComponent().getClassName();

    try {
        Class activityClass = Class.forName(className);
        notificationBuilder.setContentIntent(createContentIntent(activityClass));
    } catch (Exception e) {
        // do nothing
    }

    if (fetchArtUrl != null) {
        fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder);
    }

    return notificationBuilder.build();
}