Equalizing the audio of another app - how to? - java

i need to make a Equalizer for Android.
El audio session ID 0 is deprecated.
Is there a way to get the current audio session ID?
I want to equalize from my app the sound of other apps.
In Google play there are other apps that use the "compatibility mode". but i do not know how they do it. For example, the app detects that spotify is playing, the session is selected and it can equalized.
Does anyone know how do this?
Thanks.
Example applications:
https://play.google.com/store/apps/details?id=com.devdnua.equalizer.free
https://play.google.com/store/apps/details?id=devdnua.equalizerp.free

According to Android, you can use ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION to receive the id of a playing audio session:
Intent to signal to the effect control application or service that a new audio session is opened and requires audio effects to be applied.
I tried adding the constant (and many others) in the manifest, but it only worked for music apps such as Spotify and Youtube Music:
<receiver android:name=".receivers.AudioSessionReceiver">
<intent-filter>
<action android:name="android.media.action.OPEN_AUDIO_EFFECT_CONTROL_SESSION"/>
</intent-filter>
</receiver>
Then, you can use the id to create an equalizer attached to the session id.
public class AudioSessionReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
int id = intent.getIntExtra(Equalizer.EXTRA_AUDIO_SESSION, -1);
String packageName = intent.getStringExtra(Equalizer.EXTRA_PACKAGE_NAME);
}
}
When I play my own media file (with my own test app), there are equalizer apps that still work on it even though I didn't broadcast the session id of my media player. So there must be a solution involving a Service that doesn't rely on Broadcast Receivers.

Related

my app doesn't send any notifications when it's not running (killed)

I have a reminder app that sends a notification according to the time of the item in the listview, the problem is that whenever my phone is rebooted or the app is killed, the app doesn't send any notification.
Note: The app is offline and local, it doesn't use internet connection, I don't use FCM or and online services for this app.
Thank you so much for your time.
Update:
I'm using a thread that searches for data in the local database, If there are any changes in time in the database compared to the current time, the notification should show, but the notification only shows when the app is running, but when the app is killed it doesn't show.
The app needs to run on android 5+,
You can use Broadcast receiver in order to be notified when Boot Completes. And again start the required services of your app.
For reference, have a look here.
This is because when you are killing the app, the onDestroy method gets called. When it's killed, you app is not doing anything. For this you would need a broadcast receiver.
How to implement broadcast receiver?
Create a java class named TimeBradcastReceiver.java.
Paste this code in the class
public class TimeBradcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
String dateString = Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE);
String hourString = Calendar.getInstance().get(Calendar.HOUR);
String minutesString = Calendar.getInstance().get(Calendar.MINUTE;
Log.d("MyBradcastReceiver","i have recieved - " + dateString);
}
}
Once you have implemented this code, you need to add this to you manifest inside the application tag.
<receiver android:name="com.chatverse.free.TimeBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.TIME_TICK"/>
</intent-filter>
</receiver>
Add this code to your activity which opens the first.
IntentFilter mTime = new IntentFilter(Intent.ACTION_TIME_TICK);
registerReceiver(new TimeBradcastReceiver(), mTime);
Now you can do the comparison of the dates and hours and show the notification.
Note - This receiver will update only when a minute has changed.

Android app not receiving FCM push notification from Python Server (iOS is)

I'm working on making an Android version of an iOS app I made earlier this year.
I have a Python Flask API that is supposed to send a push notification via Firebase Cloud Messaging to Android and iOS devices when a certain endpoint is called.
My iOS app is working perfectly, but on Android I don't receive any notifications (neither in foreground nor background).
In my Python code, I'm using a MulticastMessage:
push_notification = messaging.MulticastMessage(
device_tokens,
notification=messaging.Notification(title=title, body=message),
data=data,
apns=messaging.APNSConfig(
payload=messaging.APNSPayload(
messaging.Aps(sound="default")
)
),
android=messaging.AndroidConfig(
notification=messaging.AndroidNotification(
sound="default"
)
)
)
response = messaging.send_multicast(push_notification)
device_tokens is a list of the registration tokens of the devices I want to send the notification to. I verified that one of the tokens is, indeed, the token that my Android Client is using.
data is a dictionary of the following form:
{
"uid": "<user-uid-here>"
}
On the client side, I tried to follow the documentation pretty closely. I added my google-services.json file, added and applied the plugin in the Gradle files, and added the Firebase Messaging dependency. Then I created a Messaging Service and updated my app manifest:
MessagingService.java
public class MessagingService extends FirebaseMessagingService {
public MessagingService() {
super();
}
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Log.w("Debug", "RECEIVED MESSAGE");
}
}
AndroidManifest.xml
<!--Inside application tag-->
<service
android:name=".model.MessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="#mipmap/ic_launcher" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="#color/colorAccent" />
I should mention that at some point it was sort of working (sometimes I would get the notification, sometimes I wouldn't), but I can't remember exactly what I did that broke it (if I did do anything at all).
I've Googled in a lot of places, but nothing seems to be working.
Am I missing something? I'm pretty confident the problem is not with the server, since the iOS app is handling the notifications just fine.
NOTE: I want to be able to receive messages from both foreground and background state.
EDIT: I am running this on an emulator; perhaps that might be related to the problem? I remember sometimes before the device wouldn't get the notification for a long time...

Unable to receive BluetoothA2dp.ACTION_PLAYING_STATE_CHANGED broadcast

Background :
Developing application to make android phone A2DP receiver.
BlueDroid stack supports A2DP sink, but it's disabled by default.
Modified source code to enable A2DP. Android phone is seen as HeadsFree Device and is connectable.
Problem :
I can't hear sound.
Tried :
A2dpSinkStateMachine class is in charge of acting android as A2dpSink. One of the state is Connected, it has method broadcastAudioState, which is called when audio starts/stops streaming. (line 579)
broadcastAudioState sends broadcast with action BluetoothA2dpSink.ACTION_PLAYING_STATE_CHANGED (line 696) and writes log A2DP Playing state....))
Registered broadcast receiver
- tried via manifest.xml file
<receiver android:name=".PlayingStateChangeBroadcastReceiver">
<intent-filter>
<action android:name="android.bluetooth.a2dp.profile.action.PLAYING_STATE_CHANGED" />
</intent-filter>
</receiver>
- dynamically too
Intent intent =
registerReceiver(mReceiver, new IntentFilter(BluetoothA2dp.ACTION_PLAYING_STATE_CHANGED));
- dynamically with permission
Intent intent =
registerReceiver(
mReceiver,
new IntentFilter(BluetoothA2dp.ACTION_PLAYING_STATE_CHANGED),
"android.permission.BLUETOOTH",
new Handler(Looper.getMainLooper()));
onReceive method is never called.
Additionally:
while registering dynamically registerReceiver returns null.
inside Android monitor window, i see log A2DP Playing state ..., meaning broadcast is sent.
android.bluetooth.a2dp-sink.profile.action.PLAYING_STATE_CHANGED is declared as <protected-broadcast> in platform/frameworks/base/core/res/AndroidManifest.xml file
Any ideas, how to fix that ?
Thanks

Intent extra on WallpaperManager's broadcast receiver

I'm building a wallpaper application.
I have a button which sets the wallpaper.
What I would like to do is to check if the wallpaper is downloaded, if yes set the wallpaper - if not, download and set the wallpaper.
I check if a file with an ID (e.g. 26748.jpg) exists, if yes I successfully set the wallpaper, if it doesn't exist, I download it - but I'm unable to set it.
I'm have a BroadcastReceiver set up:
<receiver android:name=".SinglePhotoActivity$CheckDownloadComplete">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</receiver>
which displays a simple saved message:
public static class CheckDownloadComplete extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Saved!", Toast.LENGTH_SHORT).show();
}
}
The problem is that I have two types of setting the wallpaper: one if the wallpaper is already downloaded, and one if it isn't. I've done a little research and found out that broadcast receivers of this type cannot really contain any intent extras. The only thing I could do is set a description on my DownloadManager's request and then check the description in onReceive.
So, if the image is already downloaded, I'd like to display a simple Toast. If not, then download it and after, in OnReceive after the download has completed run my setWallpaper code.
Is there any more proficient way of doing this?

Android API for detecting new media from inbuilt camera & mic

Is there any elegant way in the Android API for detecting new media when it is written to the device? I’m mainly interested in photos taken by the camera, video taken by the camera and audio recorded from the mic.
My current thinking is to periodically scan each media content provider and filter based on last scan time.
I’m just wondering if there is some service I can get realtime notifications.
There's a special broadcast Intent that should get called every time an application writes anything new to the Media Store:
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE
The Broadcast Intent includes the path to the new file, accessible through the Intent.getDataString() method.
To listen for it, just create a BroadcastReceiver and register it using an IntentFilter as shown below:
registerReceiver(new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
String newFileURL = intent.getDataString();
// TODO React to new Media here.
}
}, new IntentFilter(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE));
This will only work for files being inserted into one of the Media Store Content Providers. Also, it depends on the application that's putting it there broadcasting the intent, which all the native (Google) application do.
Aha!
A content observer is what i need!
Here's where i found out about it

Categories