Hi Community,
I have problems with the ACTION_MEDIA_BUTTON - Intent. I can't get my App receiving those actions and react on them.
In my AndroidManifest.xml I added the Intent-filter:
Code:
<intent-filter android:priority="42">
<action android:name="android.intent.action.MEDIA_BUTTON">
</intent-filter>
And in the onCreate-Method I registered a Receiver:
Code:
BroadcastReceiver receiver;
if (receiver == null) {
receiver = new ButtonReceiver();
}
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MEDIA_BUTTON);
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
registerReceiver(receiver, filter);
And the corresponding ButtonReceiver-class:
Code:
class ButtonReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
String intentAction = intent.getAction();
if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction))
{
Log.d("ButtonReceiver", "I will handle buttons here");
//handle buttons
}
}
}
The app compiles fine and is also running without problems, BUT I never get to the "//handle buttons"-section.
For testing purpose I'm using my Jabra BT2015 and the provided earphones from HTC. Both don't work.
Every hint is very appreciated.
Greez
LordAlien
hello
I would like to get the values from a sample of an ambient sounds phone absorbs from it's surroundings. how can I able to do so?
i.e how do I sample, and then how do I get values, and in which form?
thanks,
Doron
i know no way of getting the sound levels from the mic without recording a file and doing some sort of audio analysis on it.
see http://developer.android.com/reference/android/media/MediaRecorder.html
and (not my code...)
Code:
public class AudioRecorder {
final MediaRecorder recorder = new MediaRecorder();
final String path;
/**
* Creates a new audio recording at the given path (relative to root of SD card).
*/
public AudioRecorder(String path) {
this.path = sanitizePath(path);
}
private String sanitizePath(String path) {
if (!path.startsWith("/")) {
path = "/" + path;
}
if (!path.contains(".")) {
path += ".3gp";
}
return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
}
/**
* Starts a new recording.
*/
public void start() throws IOException {
String state = android.os.Environment.getExternalStorageState();
if(!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
throw new IOException("SD Card is not mounted. It is " + state + ".");
}
// make sure the directory we plan to store the recording in exists
File directory = new File(path).getParentFile();
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Path to file could not be created.");
}
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
recorder.prepare();
recorder.start();
}
/**
* Stops a recording that has been previously started.
*/
public void stop() throws IOException {
recorder.stop();
recorder.release();
}
}
thanks a lot.
Hi, I've this method that looks for the IP of my device:
Code:
public String getLocalIpAddress(boolean useIPv4){
String ritorno="";
try{ List<NetworkInterface>interfaces=Collection.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface intf : interfaces) {
List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
for (InetAddress addr : addrs) {
if (!addr.isLoopbackAddress()) {
String sAddr = addr.getHostAddress().toUpperCase();
boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
if (useIPv4) {
if (isIPv4)
ritorno=sAddr;
} else {
if (!isIPv4) {
int delim = sAddr.indexOf('%'); // drop ip6 port suffix
return delim<0 ? sAddr : sAddr.substring(0, delim);
}
}
}
}
}
} catch (Exception ex) { } // for now eat exceptions
return ritorno;
Now, the issue is that when I do intf.getInetAddresses(), I get a collection of the addresses bound to intf, but I need the address relative to the last connection. How can I solve my issue?
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
I am a person who needs many many multiple alarms to wake up early in the morning.
Every clock/alarm applications I tried has no feature that turning on or off all alarms at once.
So I decided to customize google's official android clock app.
Let's get it started.
### Needed #####
google's clock app source (I use Lollipop's source for my device)
buttons icon image
### Steps #####
1) download source from googlesource.com repository
android system clock application's package name is "DeskClock".
You can clone the source like below
Code:
git clone -b lollipop-release https://android.googlesource.com/platform/packages/apps/DeskClock
2. import it & remove errors
When you import the project to your IDE, you will get thousand of import errors.
Check below
SDK Version
- Make sure that you have lollipop sdk and check "Build Target" in "Project Properties"
AndroidManifest
- Specify min/targetSdkVersion, if it is not in AndroidManifest.xml
- There is "DEVICE_POWER" permission because it is android system app but we can't build system application so just remove it. (In my usage, it seems to be no problem)
Library
- Put android support-library jar file and add it to project build path.
3. Add button icons
- add ic_all_on.png, ic_all_off.png as drawable
4. Edit the sources
There is "DeskClockFragmet" class which is parent of alam/timer/stopwatch/clock's Fragment class.
It uses common layout "desk_clock.xml". It has three buttons (Fab, sub buttons) in the bottom of the screen and Alarm Fragment does not use and just hide sub buttons.
Which means we can easily add buttons to that place.
setLeftRightButtonAppearance() in AlarmClockFragment.java
Code:
@Override
public void setLeftRightButtonAppearance() {
final DeskClock activity = (DeskClock) getActivity();
if (mLeftButton == null || mRightButton == null ||
activity.getSelectedTab() != DeskClock.ALARM_TAB_INDEX) {
return;
}
[COLOR="SeaGreen"] // mLeftButton.setVisibility(View.INVISIBLE);
//mRightButton.setVisibility(View.INVISIBLE);
mLeftButton.setEnabled(true);
mRightButton.setEnabled(true);
mLeftButton.setVisibility(View.VISIBLE);
mRightButton.setVisibility(View.VISIBLE);
mLeftButton.setImageResource(R.drawable.ic_all_off);
mRightButton.setImageResource(R.drawable.ic_all_on);[/COLOR]
}
set mLeft/RightButton enabled and change visibilty to VISIBLE, set button image as drawable we added.
Override onLeftButtonClick/onRightButtonClick() from parent (DeskClockFragment.class) and call switchAlarms() what we will implement.
Code:
@Override
public void onLeftButtonClick(View view) {
super.onLeftButtonClick(view);
mAdapter.switchAlarms(false);
Toast.makeText(getActivity(), "Every Alarms Disabled!!", Toast.LENGTH_SHORT).show();
}
@Override
public void onRightButtonClick(View view) {
super.onRightButtonClick(view);
mAdapter.switchAlarms(true);
Toast.makeText(getActivity(), "Every Alarms Enabled!!", Toast.LENGTH_SHORT).show();
}
+ I just hide menu button in bottom-right just in alarm tab because right and menu button are overlayed.
onCreateView() in AlarmClockFragment.java
Code:
if (menuButton != null) {
// if (isLandscape) {
// menuButton.setVisibility(View.GONE);
// } else {
// menuButton.setVisibility(View.VISIBLE);
// setupFakeOverflowMenuButton(menuButton);
// }
//remove menu button
menuButton.setVisibility(View.GONE);
}
There is AlarmItemAdapter sub class in AlarmClockFragment.java which extends CursorAdapter.
We have to implement something that change actual alarm data in inner database and change views depend on each alarm's on/off value.
I just added a method "swichAlarms" into this sub class to do that.
boolean enabled value is passed as parameter (on : true / off : false)
Get every alarm's view and change the view when the alarm on/off status has to be changed
Also there's a way to get alarms llist in Alarm.java that is getAlarms() method.
I use it to get alarms list a alarm's enabled value is different.
And change alarms enabled value with asyncUpdateAlarm() method in AlarmClockFragment.java
That's all!
easy?
Code:
// added by donghe
/**
* A convenience method to enable or disable every alarm.
* Get child view (visible view) in alarm list and changing ItemAlpha whether if its enabled value is different
* Get alarm(s) linked list from Alarms Class only if the alarm has to be updated.
* Do asynchronous updating.
* @param enabled true for turning on, false for turning off
*/
private void switchAlarms(boolean enabled) {
int totalLength = mList.getCount();
for (int i = 0; i < totalLength; i++) {
View v = mList.getChildAt(i);
if (v != null) {
ItemHolder h = (ItemHolder)(v.getTag());
if (h != null && h.alarm.enabled != enabled) {
setDigitalTimeAlpha(h, enabled);
}
}
}
String selection = null;
if(enabled){
selection = "ENABLED = 0";
}
else{
selection = "ENABLED = 1";
}
ContentResolver cr = getActivity().getApplicationContext().getContentResolver();
List<Alarm> alarmList = Alarm.getAlarms(cr, selection, null);
for(Alarm alarm: alarmList){
alarm.enabled = enabled;
asyncUpdateAlarm(alarm, false);
}
}
Now I feel comfortable to sleep lately in the evening and wake up early in the morning
Hope this thread is helpful to someone like me.
I attached project archive and apk.
Enjoy it!
Thanks men!
Hi all
I rarely post in XDA becau I havehave nothing to share. But today I am happy to share this a little thing.
For audio of Note2 N7100, have two matters : 1)Volume limit for some local, and for others seems not limit but still small sound, not enough for a high resistance headphone which over 150Ohm. 2) Distort and include auto interrupt power (sound stop) due to Headphones volume trick (mostly from original 55dB to 57dB or 60dB and 63dB as in some kernel/app or flashzip).
Now start. We need a rooted device Note2 (also for S3, Note3, S4 ) and Root Browser app (on google market)
Use Root browser (other app can do but recommend root browser) to access
\system\etc\sound\t03g. Base on device and Android version, if not found, it will be at \system\etc\default_gain.conf
Open it and you see extractly or similar to this
And this
That's all! Those values are different from your original, I changed them.
You see 3 elements related to volume
Headphones volume
Aif1dac volume
Dac1 volume
I have read specs of DAC chip WM1811 in Note2 from maker's homepage.
All volume level of components are 96 to 100dB (means over 100 is out of range or with distortion). But, actually those value I confirmed OK : sounds bigger and better.
Headphone volume is limit at 63 on Note2, 64 will cause no sound. On high impedance HP as 300Ohm, 63 also make overpowered of sound chip and it stops player.
It is not a good item to change
Aif1dac (audio interface 1) is reduce because I want to use more volume from Dac1
(Main audio use dac1, other as call, mic, FM on aif2, dac2 if I don't misreading).
For Dac1 volume we can choose 96(original) to 128 (over that makes no sound). I run near max value and never found audio interrupted or any thing happens, not heating, no distortion.
Lastly Audio path DAC to headphone mux val. =0 (original ="mixer")
Test it and feel. Have fun!
This was really useful, thank you.
I changed the values for headset, headphones and aux DAC. I'm happy with analogue dock out, speaker, in-call values etc. and I don't use a bluetooth headset. I also didn't change any of the loop values as I'm sure Samsung know much better than me about this stuff as I know nothing!
Original headset values:
Code:
Modifier "Normal" {
SupportedDevice {
"Headset Out"
}
Enable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Headphone Volume", 49 },
}
Disable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "Headphone Volume", 50 },
}
}
New headset values:
Code:
Modifier "Normal" {
SupportedDevice {
"Headset Out"
}
Enable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 100 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 100 },
{ "Left Output Mixer DAC Volume", 7 },
{ "Right Output Mixer DAC Volume", 7 },
{ "Headphone Volume", 63 },
}
Disable {
{ "Headphone ZC Switch", 0 },
{ "AIF1DAC1 Volume", 100 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 100 },
{ "Headphone Volume", 63 },
}
}
Headphone changes are as above.
Original AUX Digital Out values:
Code:
Modifier "Normal" {
SupportedDevice {
"AUX Digital Out"
}
Enable {
{ "AIF1DAC1 Volume", 96 },
}
Disable {
{ "AIF1DAC1 Volume", 96 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 96 },
{ "SPKL DAC1 Volume", 1 },
{ "SPKR DAC1 Volume", 1 },
{ "Speaker Mixer Volume", 0 },
{ "Speaker Volume", 57 },
{ "Speaker Boost Volume", 0 },
}
}
New AUX Digital Out values:
Code:
Modifier "Normal" {
SupportedDevice {
"AUX Digital Out"
}
Enable {
{ "AIF1DAC1 Volume", 100 },
}
Disable {
{ "AIF1DAC1 Volume", 100 },
{ "AIF1 Boost Volume", 0 },
{ "DAC1 Volume", 100 },
{ "SPKL DAC1 Volume", 1 },
{ "SPKR DAC1 Volume", 1 },
{ "Speaker Mixer Volume", 0 },
{ "Speaker Volume", 63 },
{ "Speaker Boost Volume", 0 },
}
}
I rebooted and checked with Samsung HS330 headset, a standard headphone (no mic or call controls) and also with my FiiO E7 USB DAC/Amp connected via USB OTG cable. I get a convenient volume increase in each case, no extra system noise, no audible distortion and nothing went wrong ...so far.
Rocking on Dr. Ketan V14. Thanks a Ton !!!