Background:
I recently purchased a Motorola XOOM Tablet along with the Desktop Dock and Bluetooth Keyboard accessories.
The dock and keyboard work great, but when I take the tablet off the dock to move away from my desk, the keyboard still remains paired with the device and I have to manually change the settings to use the soft keyboard. The same goes for when I set it back on the dock, I need to manually switch it back. It's not a huge problem, but it would be nice not to have to think about it.
So I tried downloading an app from the market that simply toggled Bluetooth on and off when connected or disconnected from a power source, which worked well for a while, but the background service would die after period and become useless until I manually restarted that.
TO THE POINT: I'm trying to write a little app/service for my tablet that will recognize when it has been docked/undocked and switch the "Use Physical Keyboard" setting accordingly.
I have started with a BroadcastReciever to recognize the Dock State:
public class DockBroadcastReciever extends BroadcastReceiver {
private final String DOCK_STATE_LABEL = "android.intent.extra.DOCK_STATE";
#Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
String message = (extras.getInt(DOCK_STATE_LABEL) == Intent.EXTRA_DOCK_STATE_UNDOCKED) ? "Undocked" : "Docked";
Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
toast.show();
}
}
But I'm having trouble figuring out the best way to update the setting after the event is fired. I've poked around some examples using InputMethodManager, but all the methods seem to need a specific EditText or some other input to bind to.
Furthermore, I can't seem to find a corresponding constant that represents that setting anywhere in the docs, but graphically, it is located here: http://i.stack.imgur.com/esFaw.png
Can anyone help me out with this?
I would like for there to be a solution for changing the setting, but I am open to other ideas as well.
I have an app that does something similar. It can toggle wifi and bluetooth based on power.
You'll need to register some of this stuff in the AndroidManifest.xml file.
http://code.google.com/p/futonic-wifioncall/source/browse/AndroidManifest.xml
Project Open Source Site: http://code.google.com/p/futonic-wifioncall/
This isn't the solution but hopefully will give guidance on what you're trying to accomplish.
Related
I am working in an application for normal smartphones and I am creating new layouts for Android TV (using only a dpad).
The device that I use to try the layout, seems not to be an "official" television. Indeed the tag "television"
television: Device is displaying on a television, providing a "ten foot" experience where its UI is on a large screen that the user is far away from, primarily oriented around DPAD or other non-pointer interaction
does not work and also the example
public static final String TAG = "DeviceTypeRuntimeCheck";
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
Log.d(TAG, "Running on a TV Device")
} else {
Log.d(TAG, "Running on a non-TV Device")
}
taken from here gives me the result "Running on a non-TV device".
Well, right now I am solving the problem creating layouts using the tag "notouch", but I would like to force my "non official" TV to behavies as a TV. I was thinking in something similar to
uiModeManager.setCurrentModeType(Configuration.UI_MODE_TYPE_TELEVISION)
but in the offical documentation of UiModeManager it seems this method does not exist.
Is there some option to force a device to act as a television and not using the workaround with "notouch"?
I know that maybe most of you will suggest "not" to change the default settings of a device, but also for curiosity, could it be possible? Can you force Android to use, for example, the "small" tag with large screen size or something like this? I know that it could be possible (even if not suggested) with language, but for the screen?
I'm building an Android Wear app and trying to implement BoxInsetLayout for round screens. In my code, I want to detect if the device is round or not, so I'm using BoxInsetLayout's isRound() function, but it always returns false, even on the Moto 360.
Anyone know if there's a way to programmatically tell if the device is round?
The problem may be caused by calling isRound() at the wrong time. The round-ness is determined by the WindowInsets being delivered to the BoxInsetLayout. If you call isRound() very early before the insets have been delivered, you will get the wrong answer.
So if you have a "box" object which is the BoxInsetLayout, you would do this:
box.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
#Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
// Need to also call the original insets since we have overridden the original
// https://developer.android.com/reference/android/view/View.OnApplyWindowInsetsListener.html
box.onApplyWindowInsets(windowInsets);
// You can make calls to detect isRound() here!
// Return the insets so the BoxInsetLayout still works properly
return windowInsets;
}
});
Can you please send us the code related to the BoxInsetLayout that you are using?
According to Wayne answer on G+ it is a bug, for now we know what causes it, how to avoid it but only if user is aware of that, but fix for it is not released (yet).
https://plus.google.com/108847189842978537754/posts/5YiYb14i7ss
Quoting as post might be deleted/changed:
The problem is triggered by the watch switching languages when pairing with a phone after a factory reset. You can avoid the issue by
selecting the same language on the wearable as you are using on the
phone, so that no change occurs afterwards when the devices are
paired.
Instructions to fix the problem:
Factory reset the Moto 360.
When the wearable restarts, it will ask what language you would like to use. Select the same language that you are using on the phone
(do not select the default of English)
On the phone, start the Android Wear companion app, and select from the overflow menu the option "Pair with a new wearable".
Pair the phone with the Moto 360.
EDIT:
Using setOnApplyWindowInsetsListener (suggested by Wayne) I created small class that simplify using it a bit. https://github.com/tajchert/ShapeWear
Just copy ShapeWear.java class, and subscribe to screen shape detection event setOnShapeChangeListener() or call method ShapeWear.isRound() (can throw error is shape is not yet determined) or ShapeWear. getShape() - which can result in ShapeWear.SHAPE_UNSURE in same situation.
I am working in Android App that should prevent the user to use the mobile in some-cases .
So I tried to lock the screen
I used the PowerManger goToSleeo() Method
but it needs DEVICE_POWER permission. which is allowed only for the System apps, but my app is not a system app
what should I do ?
here is my code
PowerManager manager = (PowerManager) getSystemService(Context.POWER_SERVICE);
manager.goToSleep(600000);
Counterquestion: What purpose would it serve if normal apps could lock your screen? In my eyes, that's malware. You need the permission and nothing will ever change that. The only solution is to remove this "functionality".
Edit: Some more information by the way: Android What permissions required to call PowerManager.goToSleep(n) put device in sleep mode?
This sort of thing is difficult to do in Android for reason. You are trying to block access to the main OS, which is a bad thing. As other people have mentioned this could be used for malicious purposes (it is not a stretch to think someone could create a ransom-ware app that blocks your device, until you pay something to release it).
So bottom line - you CANNOT do what you are asking (and for good reasons). Especially on a non-rooted phone. One a device is rooted, you CAN do anything (including blocking access to the system buttons).
For more details about this, look into 'Kiosk' mode, or blocking system access (there are many SO questions about this).
You don't want to lock the device, that's deliberately designed against. You can, however, disable touch input by overriding onTouchEvent.
You then need to create a view, like so:
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<your code here>
<Disabletouch
android:id="#+id/black_hole"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
And define it like so:
public class DisableTouch extends View {
private boolean touch_disabled=true;
#Override
public boolean onTouchEvent(MotionEvent e) {
return touch_disabled;
}
public disable_touch(boolean b) {
touch_disabled=b;
}
}
Call it in the activity:
(DisableTouch) black_hole = findViewById(R.id.black_hole);
black_hole.disable_touch(true);
And reverse:
black_hole.disable_touch(false);
The FIT Radio App uses a MediaRoute.Callback that is initialized in my CommandInterface class, that controls playback for the normal audio as well as the Chromecast audio. The NowPlayingActivity is initially set as the mMediaRouteButtonHandler inside of the MediaRoute.Callback, only if the MediaRouteButton exists.
The now_playing.xml is now in the default layout, with protective measures in the java source code. Our first measure of protection against null pointer exceptions (with the G2) was removing the the MediaRouteButton from the default layout. The second measure that was taken to stop the null pointer exceptions was to add the null check in the NowPlayingActivity.setVisibility(int visibility) code sample below for any other version that may not provide the Button (N7, etc.).
The MediaRouter callback is added in the NowPlayingActvity.onResume(), and removed in the NowPlayingActvity.onPause(). The following sample displays the visibility handling in the MediaRoute.Callback.onRouteAdded:
public void onRouteAdded(MediaRouter router, RouteInfo route) {
if(hasMediaRouteButtonHandler()) mMediaRouteButtonHandler.setVisibility(View.VISIBLE);
++mRouteCount;
}
I have access to a Google G2, a Note 3, a Samsung S III, HTC One M7, and a Nexus 7. After starting the MediaRoute.Callback, the MediaRoute Button shows on all devices [using NowPlayingActivity.setVisibility(int visibility)], except with the Nexus 7 and the Google G2.
public void setVisibility(int visibility) {
if(getMediaRouteButton() != null) getMediaRouteButton().setVisibility(visibility);
}
I am using the findViewById(int) method in the NowPlayingActvity and it returns null in the latter cases (Nexus 7 & G2), but works on the S III, HTC One, and Note 3.
public MediaRouteButton getMediaRouteButton() {
return (MediaRouteButton) findViewById(R.id.media_route_button);
}
I have looked on StackOverflow for similar questions, and there were no real answers for the issue:
With the first question that I found the user figured it out eventually, and posted that he had no clear solution.
android.support.v7.app.MediaRouteButton does not display
Another question was answered by the poster, and the solution came from using a real device instead of the emulator:
Why my MediaRouteButton not available to find any cast devices?
I have debugged this with all the above devices, with Dirk (My Contractee) over my shoulder! So this is a critical issue guys, and we really need your help!
Thanks in advance,
Christopher Miller, posting on behalf of Dirk # Fit Radio.
I have to open device dock setting through code. I searched but not got proper solution. In samsung galaxy s-3 it goes through settings->Accessory. I tried following code but didn't work
startActivityForResult(new Intent(Settings.System.getString(getContentResolver(), DOCK_SETTING)), 0);
Correct me if I'm wrong, but I believe the reason this doesn't work, (and why you weren't able to find the appropriate Activity Action in the Android Settings), is because Accessory appears to be provided by Samsung for its Galaxy devices. Therefore, you won't be able to find it in the standard Android SDK (yet?).
I'm currently trying to figure out a workaround, so I'll edit this post if I find a solution.
EDIT: Looks like JoxTraex found a way for you to edit the settings via:
Settings.System.putInt(getContentResolver(), "dock_sounds_enabled", 1);
In addition, if you need to modify these settings when the user has docked their device, you should create a BroadcastReceiver to listen for the ACTION_DOCK_EVENT broadcast.
I was able to achieve this through looking at the settings and configuring the setting programatically:
android.provider.Settings.System.putInt(getContentResolver(), "dock_sounds_enabled", 1);
You need the permission:
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
The code above will write to the settings that enables the dock sound settings on the samsung s3. However; instead of just writing it you should tell the user that the setting is disabled and you need it enabled and allow the user to confirm they want to enable it via a dialog.
On another note, I don't think its possible to go directly to the settings->accessory screen because its was a custom settings added by Samsung. This action is not provided in the Android SDK, so it would take a while to derive what is the actual action or even if it exists.
And if you want to confirm it just query it:
String where = "name = 'dock_sounds_enabled'";
Cursor c = getContentResolver().query(android.provider.Settings.System.CONTENT_URI, null, where, null, null);
Update
Steps for how to handle the dialog's response for configuring the dock setting:
Grab the setting.. if it's 0, bring up the dialog to enable it, otherwise continue with your processing
Once the dialog is up and the user confirms they want to enable it:
Confirm: Put a 1 into the dock sounds then close the dialog
Deny: Don't set the dock setting then close dialog