Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send media action on android

Tags:

I'm looking for a way to send global media action (Play/pause, Next, Previous) to the phone, much like it can take it froma bluetooth paired radio/speaker.

I have found the MediaController class (http://developer.android.com/reference/android/widget/MediaController.html) but it seem more to be to implement the receiver of those action and i'm looking for a sender.

However, I can't seam to find any reference to this anywhere in the android doc...

Anyone already stumble on this ?

like image 424
Remy Grandin Avatar asked Jun 18 '15 09:06

Remy Grandin


People also ask

Where is files and media permission Android?

On the Settings > Privacy > Permission manager > Files and media page, each app that has the permission is listed under Allowed for all files. If your app targets Android 11, keep in mind that this access to "all files" is read-only.

How do I transfer data from one app to another Android?

Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.

What are media files on Android?

Manage downloaded music, movies, and podcasts The biggest space suckers on your Android phone are media files. Those albums that you downloaded for a camping trip or a movie for a long plane ride that you simply forgot about can eat up lots of data.

What is shared storage on Android?

Shared storage: Store files that your app intends to share with other apps, including media, documents, and other files. Preferences: Store private, primitive data in key-value pairs. Databases: Store structured data in a private database using the Room persistence library.


1 Answers

So if your activity is called MainActivity you can do:

//for play/pause toggle Intent i = new Intent("com.android.music.musicservicecommand"); i.putExtra("command", "togglepause"); MainActivity.this.sendBroadcast(i);  //for next Intent i = new Intent("com.android.music.musicservicecommand"); i.putExtra("command", "next"); MainActivity.this.sendBroadcast(i);  //for prev Intent i = new Intent("com.android.music.musicservicecommand"); i.putExtra("command", "previous"); MainActivity.this.sendBroadcast(i);  //to change volume audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, *value*, AudioManager.FLAG_SHOW_UI); 
like image 186
jrsall92 Avatar answered Oct 05 '22 23:10

jrsall92