I am developing an App that has a lock screen widget where it has a play, pause, prev and next. When I connect my phone to an Android wear, it automatically shows this buttons and it works fine. I would like to add a "Like" button that would automatically be shown on the lock screen and the android wear. I know that I can create a Notification and add action for the like. But I want to know if is it possible to achieve that using only RemoteControlClient?
Have you tried using rating with the flag FLAG_KEY_MEDIA_RATING ? It seems that it's the only way to maintain generic methods and avoid having to set custom code on the wear side (or through notifications).
This flag can be set with setTransportControlFlags
Flag indicating a RemoteControlClient supports ratings. This flag must
be set in order for components that display the RemoteControlClient
information, to display ratings information, and, if ratings are
declared editable (by calling addEditableKey(int) with the
RATING_KEY_BY_USER key), it will enable the user to rate the media,
with values being received through the interface set with
setMetadataUpdateListener(OnMetadataUpdateListener).
Unfortunately, few or not example exists on the web. I discovered only one (unanswered) question relative to this on SO :
Android 4.4 KitKat Rating API
Related
I'm making a settings activity in my Android video playback app and I want to know if it was possible to enable/disable PIP(Picture-in-Picture) mode programmatically.
To clarify I am fully aware that this setting can be change via application advanced settings or via special app access, but I want to leave that as a last resort. (If there are no other alternatives).
Further more this Activity is isolated from the video threading page itself.(Meaning the user would have to stop the video entirely before coming to this page).
Main reasons I want this is an extra reminder that this app supports this feature and also if the user forgets where to reactivate this function.
Think of it as: Adding another layer of user friendliness
Here is a way to check the setting:
AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
return (AppOpsManager.MODE_ALLOWED == appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_PICTURE_IN_PICTURE,
context.getApplicationInfo().uid, context.getPackageName()));
I haven't tried setting it programmatically, but this could be a starting point for you.
I have an Android app with 9 buttons. This app runs on 2.36 and is the only app on the device (or at least the only app we let the user use - we ship the device with our code preinstalled as part of a suite of industrial products we sell.)
All the buttons go to the same handler and get sorted out there by their tag. The handler is specified in the XML:
<Button android:id="#+id/IdleButton"
android:layout_marginLeft="5dp"
android:background="#drawable/idle18pt_he_normal"
android:hapticFeedbackEnabled="true"
android:layout_width="92dp"
android:layout_height="92dp"
android:tag="0"
android:onClick="theButtonHandler">
</Button>
I want to enable haptic feedback, i.e., a vibration, when the user presses the button. Is there a way to do this just in the XML, or if not, is there a way to do it in my onClick() handler?
The web examples I've seen (e.g., http://androidcookbook.com/Recipe.seam?recipeId=1242 ) for haptic feedback on Android mostly seem to involve changes to the manifest, changes to the XML (you can see I've already enabled it in my XML, above) and then declaring, initializing and implementing a separate Touch handler for the button. This seems like a lot of work, especially since I have 9 buttons.
Since I already have just one onClick handler for all my buttons is there a way I can implement the haptic feedback there?
All I had to do to get a "click" sound when I tap one of my buttons was to checkmark "Audible selection" in the "Sounds" part of the phone's settings - no coding at all. Why is haptic feedback so much more complicated?
Without using the VIBRATE permission.
You can use performHapticFeedback() function of any View including Button.
For example programmatically in Kotlin:
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
This vibrates the device.
You can vibrate the device from anywhere in your Fragment or Activity, even when you don't have a View available.
In Fragment you can do:
requireView().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
In Activity you do:
window.decorView.rootView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
Create a custom VibrateButton class that inherits from Button, and add this vibration onClick. You'll still need to ask for permissions in the Manifest, so there's nothing much you can do without inheriting. This example code is taken from here, and does the vibration.
import android.os.Vibrator;
...
Vibrator v = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
// Vibrate for 500 milliseconds
v.vibrate(500);
Note:
Don't forget to include permission in AndroidManifest.xml file:
<uses-permission android:name="android.permission.VIBRATE"/>
The reason sound can be automatically set for buttons, but vibration can't, is the same it asks for permissions to allow vibration. Vibration consumes battery (way more than a simple sound), and so it affects battery duration, which needs to be, somehow, approved by the end user. If you see, in most some there's an option to "vibrate on click" for some specific buttons (keyboard apps, mainly), but that's dependant on each app.
PS: Make sure the device can vibrate. I had some hours stupidily lost when adding vibration to a Nexus 7 2012; it hasn't got a vibration module. Also, make sure you can disable that, to keep battery up longer.
Is it possible to add a google plus button added to my android app and have it linked to the one that one that is displayed at the top of the google play store , below the app name? So that when people click the button in the app, the count on the play store would go up.
According to the G+ docs, a +1 button is associated with a particular URL. So, if you can figure out what URL the +1 button in Google Play is associated to, then you should be able to construct a G+ button following the thread here (that I know you've already seen) with that URL and you should be all set. My best guess is that it's the play store URL associated with your app...http://play.google.com/store/apps/details?id=your.package
Sounds like you also want the user to end up in Google Play after they click? If so, just follow the directions here - perhaps you could subclass PlusOneButton or set some click handler on it (calling super) to allow the whole G+ functionality to work before navigating them to the Play Store.
I know this may not be an appropriate question, but I want to know how a touch enabled OS like
android detects a button in an app and calls the appropriate handler? When programming an app we just give the alignment information of a particular button. So, how android keeps the mapping between a button and screen position? I think this is kindof dynamic because if you change the screen orientation or use zoom or something like that the button positions are changed dynamically. So, android must look at the touch position and decide whether a button is there or not and call the appropriate handler. How this all things put together?
I appreciate any reply.
I have an app which uses the ACTION_MEDIA_BUTTON intent with a BroadcastReceiver to control a music player. The user pushes a button on external hardware and it controls the in-app music player. The user can also HOLD DOWN the button and change the volume.
I recently downloaded another app which uses the headset button, and it takes over the media button intent from my app! So when this other app is open and I press the button, the other app will start running, but my app will think that the button is still pressed down so it will cycle the volume.
To summarize,
my app is open, supposed to be sole listener of media button intents
other app gets opened, it also wants to be sole listener of media button intents
button gets pressed with both apps open, control goes to other app
my app thinks the button is being held down, as it lost control as the button was pressed in down mode (I think). It then launches functions I don't want launched because it thinks the user has held down the button.
Is there any way I could make sure that while my app is open it's the sole receiver of this media button intent? Could I at least check to see if another app has taken over, so I can prevent unexpected behaviour?
Thank you for any help, I've never had apps not play nicely before!
You can alter your BroadcastReceiver's priority (make it something large, like 10000): it should then get the Intent first, and then you can pass it on to the other app.
I have a similiar issue. I believe, outside of the 'arms race' over the priorites mentioned, the only real solution is to close the other application. If you are releasing this application to other users, you could possibly give them a message telling them to close other media player apps and services.
In your manifest you can set the intent priority to the max value of an integer which is: 2147483647.
You should not however set your IntentFilter priority over 1000 as it tells you in the API docs. You can set the IntentFilter priority like so:
myIntentFilter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
I assume you should subtract one from the SYSTEM_HIGH_PRIORITY constant as the docs say the value must be less than SYSTEM_HIGH_PRIORITY.
Quote from docs about IntentFilter.setPriority(int):
Applications must use a value that is larger than SYSTEM_LOW_PRIORITY and smaller than SYSTEM_HIGH_PRIORITY.