Example usage for android.content Intent CATEGORY_APP_MUSIC

List of usage examples for android.content Intent CATEGORY_APP_MUSIC

Introduction

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

Prototype

String CATEGORY_APP_MUSIC

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

Click Source Link

Document

Used with #ACTION_MAIN to launch the music application.

Usage

From source file:com.rks.musicx.services.NotificationHandler.java

public static void buildNotification(MusicXService musicXService, String what) {
    if (musicXService == null) {
        return;//ww w .jav  a  2s. c o  m
    }
    RemoteViews remoteViews = new RemoteViews(musicXService.getPackageName(), R.layout.widget);
    RemoteViews smallremoteView = new RemoteViews(musicXService.getPackageName(), R.layout.small_notification);

    Intent intent = new Intent(musicXService, PlayingActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendInt = PendingIntent.getActivity(musicXService, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(
            musicXService).setWhen(System.currentTimeMillis()).setCategory(Intent.CATEGORY_APP_MUSIC)
                    .setPriority(Notification.PRIORITY_DEFAULT).setShowWhen(false).setAutoCancel(true)
                    .setCustomBigContentView(remoteViews).setContent(smallremoteView)
                    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    remoteViews.setOnClickPendingIntent(R.id.item_view, pendInt);
    smallremoteView.setOnClickPendingIntent(R.id.small_item_view, pendInt);
    remoteViews.setTextViewText(R.id.title, musicXService.getsongTitle());
    remoteViews.setTextViewText(R.id.artist, musicXService.getsongArtistName());
    smallremoteView.setTextViewText(R.id.small_title, musicXService.getsongTitle());
    smallremoteView.setTextViewText(R.id.small_artist, musicXService.getsongArtistName());
    FavHelper favHelper = new FavHelper(musicXService);
    if (favHelper.isFavorite(musicXService.getsongId())) {
        remoteViews.setImageViewResource(R.id.action_favorite, R.drawable.ic_action_favorite);
    } else {
        remoteViews.setImageViewResource(R.id.action_favorite, R.drawable.ic_action_favorite_outline);
    }
    if (musicXService.isPlaying()) {
        builder.setSmallIcon(R.drawable.aw_ic_play);
        builder.setOngoing(true);
    } else {
        builder.setSmallIcon(R.drawable.aw_ic_pause);
        builder.setOngoing(false);
    }
    if (what.equals(PLAYSTATE_CHANGED)) {
        if (MediaPlayerSingleton.getInstance().getMediaPlayer().isPlaying()) {
            remoteViews.setImageViewResource(R.id.toggle, R.drawable.aw_ic_play);
            smallremoteView.setImageViewResource(R.id.small_toggle, R.drawable.aw_ic_play);
        } else {
            remoteViews.setImageViewResource(R.id.toggle, R.drawable.aw_ic_pause);
            smallremoteView.setImageViewResource(R.id.small_toggle, R.drawable.aw_ic_pause);
        }
    }
    handler.post(new Runnable() {
        @Override
        public void run() {
            ArtworkUtils.ArtworkLoader(musicXService, 300, 300, musicXService.getsongAlbumName(),
                    musicXService.getsongAlbumID(), new palette() {
                        @Override
                        public void palettework(Palette palette) {
                            int colors[] = Helper.getAvailableColor(musicXService, palette);
                            remoteViews.setInt(R.id.item_view, "setBackgroundColor", colors[0]);
                            remoteViews.setInt(R.id.title, "setTextColor", Color.WHITE);
                            remoteViews.setInt(R.id.artist, "setTextColor", Color.WHITE);
                            smallremoteView.setInt(R.id.small_item_view, "setBackgroundColor", colors[0]);
                            smallremoteView.setInt(R.id.small_title, "setTextColor", Color.WHITE);
                            smallremoteView.setInt(R.id.small_artist, "setTextColor", Color.WHITE);
                        }
                    }, new bitmap() {
                        @Override
                        public void bitmapwork(Bitmap bitmap) {
                            remoteViews.setImageViewBitmap(R.id.artwork, bitmap);
                            smallremoteView.setImageViewBitmap(R.id.small_artwork, bitmap);
                            NotificationManagerCompat.from(musicXService).notify(notificationID,
                                    builder.build());
                        }

                        @Override
                        public void bitmapfailed(Bitmap bitmap) {
                            remoteViews.setImageViewBitmap(R.id.artwork, bitmap);
                            smallremoteView.setImageViewBitmap(R.id.small_artwork, bitmap);
                            NotificationManagerCompat.from(musicXService).notify(notificationID,
                                    builder.build());
                        }
                    });
        }
    });
    controls(remoteViews, smallremoteView, musicXService);
}

From source file:com.rp.podemu.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);

    sharedPref = this.getSharedPreferences("PODEMU_PREFS", Context.MODE_PRIVATE);

    //String[] controlledApp = new String[appsRunning.size()];
    //Drawable[] icons = new Drawable[appsRunning.size()];
    //pm.getApplicationInfo(r.baseActivity.getPackageName(), PackageManager.GET_META_DATA);
    //Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    //startActivity(intent);

    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_APP_MUSIC);

    PackageManager pm = getPackageManager();
    String text = "";
    List<ResolveInfo> packages = pm.queryIntentActivities(intent, 0);
    //get a list of installed apps.
    //List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    //using hashset so that there will be no duplicate packages,
    //if no duplicate packages then there will be no duplicate apps
    HashSet<String> packageNames = new HashSet<String>(0);
    appInfos = new ArrayList<ApplicationInfo>(0);

    //getting package names and adding them to the hashset
    for (ResolveInfo resolveInfo : packages) {
        packageNames.add(resolveInfo.activityInfo.packageName);
    }/*from  w  ww  . j a  v a2 s.c  o  m*/

    // used just for tests
    /*
    ApplicationInfo dummyApp = new ApplicationInfo();
    dummyApp.name="select application";
    dummyApp.processName="dummy";
    appInfos.add(dummyApp);
    */

    for (String packageName : PodEmuIntentFilter.getAppList()) {
        try {
            appInfos.add(pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA));
        } catch (PackageManager.NameNotFoundException e) {
            //Do Nothing
        }
    }
    //now we have unique packages in the hashset, so get their application infos
    //and add them to the arraylist
    for (String packageName : packageNames) {
        try {
            appInfos.add(pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA));

        } catch (PackageManager.NameNotFoundException e) {
            //Do Nothing
        }
    }

    text += "Apps count: " + appInfos.size() + "\n";
    for (ApplicationInfo appInfo : appInfos) {
        //if (packageInfo.)
        {
            appInfo.name = (String) appInfo.loadLabel(pm);
            text += appInfo.loadLabel(pm) + "\n";
            //text += packageInfo.
            //text += "\n";
        }
    }

    //TextView textView = (TextView) findViewById(R.id.ctrlAppTitle);
    //textView.setText(text);

    //LauncherApps launcherApps=new LauncherApps();
    //List<LauncherActivityInfo> activities=launcherApps.getActivityList(null, android.os.Process.myUserHandle());
    //List<LauncherActivityInfo> activities=LauncherApps().getActivityList(null, android.os.Process.myUserHandle());

    baudRateList.add(9600);
    baudRateList.add(14400);
    baudRateList.add(19200);
    baudRateList.add(28800);
    baudRateList.add(38400);
    baudRateList.add(56000);
    baudRateList.add(57600);
    baudRateList.add(115200);

    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        String version = pInfo.versionName;
        TextView versionHint = (TextView) findViewById(R.id.versionHint);
        versionHint.setText(getResources().getString(R.string.version_hint) + version);
    } catch (PackageManager.NameNotFoundException e) {
        // do nothing
    }

}

From source file:com.saulcintero.moveon.MainHolder.java

@SuppressLint("InlinedApi")
@SuppressWarnings("deprecation")
@Override/*from   w  ww  .j  a v  a2s .c  o  m*/
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.coach:
        Intent i = new Intent("android.intent.action.PRACTICE_BUTTONS_STATUS");
        if (!prefs.getBoolean("blocked", false)) {
            boolean speak = prefs.getBoolean("speak", false);
            if (speak) {
                SharedPreferences.Editor editor = prefs.edit();
                editor.putBoolean("speak", false);
                editor.commit();

                TextToSpeechUtils.setSpeak(false);
            } else {
                SharedPreferences.Editor editor = prefs.edit();
                editor.putBoolean("speak", true);
                editor.commit();

                TextToSpeechUtils.setSpeak(true);
            }
            i.putExtra("practiceButtonsStatus", "1");
            sendBroadcast(i);
        }
        break;
    case R.id.camera:
        Intent i2 = new Intent("android.intent.action.TAKE_PICTURE");
        if (!prefs.getBoolean("blocked", false) && MoveOnService.getIsPracticeRunning()) {
            sendBroadcast(i2);
        }
        break;
    case R.id.padlock:
        changeLockedStatus();

        Intent i3 = new Intent("android.intent.action.PRACTICE_BUTTONS_STATUS");
        i3.putExtra("practiceButtonsStatus", "2");
        sendBroadcast(i3);
        break;
    case R.id.music:
        if (!prefs.getBoolean("blocked", false)) {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
                startActivity(new Intent(MediaStore.INTENT_ACTION_MUSIC_PLAYER));
            } else {
                Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, Intent.CATEGORY_APP_MUSIC);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
            }
        }
        break;
    case R.id.settings:
        if (!prefs.getBoolean("blocked", false))
            startActivity(new Intent(this, MoveOnPreferences.class));
        break;
    }
    return true;
}