How do I change Watch Faces programmatically - android

I've a free app on the Play Store: Circus Watch Faces and I'm trying to add a watch faces chooser in the configuration activity; I followed the Android Dev Docs about it and no problems, BUT how I can switch from one watch face to another?
I'm completely new to android development so I'm trying to understad from samples and building something new.
Currently I've a configuration activity with just a button and when I click on it, I'd like to change the current watch face!
My code is on GitHub (not updated with the config activity yet) if maybe can help a bit.

There is no way to change watch face programatically. The best you can do is send a broadcast WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER or (in the new release of Android Wear) WallpaperManager. ACTION_CHANGE_LIVE_WALLPAPER. They will invoke a watch face picker (watch faces are specialized wallpapers). The latter intent also allows you to set your watch face as a proposal for selection in the picker.
The reason for non existence of a way for setting a watch face is that it could be easily abused by apps against user's wishes.
However, since you are trying to do something from your configuration activity, maybe you want to achieve something completely different. Maybe you want to just have one WatchFaceService and then change it (draw it differently) according to some internal settings. This way if the users wants to change the appearance (even to a point where the watch face looks completely different, feels like a new watch face) you just change the underlying data and let the watch face redraw itself.

The closest you can do is the following:
public static void pickYourWatchFace(Context context) {
ComponentName yourWatchFace = new ComponentName(context, YourWatchFace.class);
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, yourWatchFace)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
this will open the Watch Face Picker with YourWatchFace in front of the user, requiring only one tap to set it up.

Related

MediaStore.Audio.Media.RECORD_SOUND_ACTION not working in nougat

I am using MediaStore.Audio.Media.RECORD_SOUND_ACTION to open sound recorder application, I am not able to open application as no default application present, then i install two voice recorder application even though not able to see these application in my chooser intent. I am using following code-
Intent soundRecorderIntent = new Intent(); // create intent
soundRecorderIntent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION); // set action
startActivityForResult(soundRecorderIntent, ACTIVITY_RECORD_SOUND); // start activity
It works well in marshmallow
The code is correct and you've probably found an app that supports the intent by now. But to prevent that others waste their time like I did, here's a quick note:
Most of the currently top rated voice recording apps in the Play Store do not provide the necessary intent filter.
That seemed so unrealistic to me that I doubted my code when it didn't work after having installed the five most popular voice recording apps. But there's a handy manifest viewer app that reveals that their manifests simply do not declare the intent filter. So, as said, the code is correct.
To save you the time from searching for a suitable app, here are two that are invocable:
Audio Recorder from Sony
Samsung Voice Recorder from Samsung
There is no requirement for a voice recorder app to support this Intent action, and apparently your device does not ship with an app that supports this Intent action either. Your code itself seems fine.
If recording is optional to your app, catch the ActivityNotFoundException and tell the user that they do not have a recorder, and perhaps suggest to them that they install one that you test that works, if you can find one.
Otherwise, record the audio yourself, using MediaRecorder.

Android: how create a button in my app that will take me to the App Manager

I'm looking to create a simple button in my android app that when clicked will take me to the app manager to a specific app where I can force close, uninstall, clear cache or data. Can someone help or point me to some examples to look at?
Use ACTION_APPLICATION_DETAILS_SETTINGS, with a package: Uri pointing to the app in question.
Note that this activity may not exist on all devices or may not be accessible by the current device user, so plan accordingly.
start following activity in your button click event.
startActivity( new Intent(android.provider.Settings.ACTION_APPLICATION_SETTINGS), 0);

Opening an Android application within another

I am trying to open a different, already installed android application within another, on click of a button. The new application should be opened in a part of the screen within the calling application.
Currently, my code creates a new intent and runs the called application in that. the calling application disappears. Here's my code:
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
PackageManager pm = getPackageManager();
Intent intent = pm.getLaunchIntentForPackage("com.ritwik.camera");
startActivity(intent);
}
});
Ideally, it should open as a part of the same screen, without sidelining the parent(calling) application. How do I do that?
When you start an Intent to execute another application (i.e. because you are implementing a launcher or a main menu replacement) you are actually asking android to execute the application identified with a specific package (or the one satisfying some specific constraints, like the ability to handle images, videos, etc), without any clue or reference about the Activities it contains (nor the ability to get any...).
Therefore I don't think that what you are trying to achieve is possible with the current version of the OS (unless some vendor is providing extensions to do just that, see the comment by Pratik).
The new application should be opened in a part of the screen within the calling application.
This is not possible with conventional third-party application UIs.
AFAIK, the split-screen feature (Adaptive UI) is supported from Android 3.0 onwards.
That has nothing to do with embedding the UI of third-party apps into your own.
So I didn't get what you meant to say by "it's not possible with the current version of the OS"
It is not available on any stock version of Android released up through March 26, 2013 at 9:50am Eastern Time.
Certain device manufacturers, like Samsung, have extended Android with multi-window capabilities. However, the control over those windows lies with the user and the (modified) OS. Unless there is something in their S-Pen SDK for this, you have no way of starting another window.
Android also has RemoteViews, which is a means of passing a simplified UI between processes. Using this, it is possible for one app to embed RemoteViews published by another app. You see this with app widgets on the home screen, for example. However, both apps have to be written with this in mind, such as an app publishing an AppWidgetProvider to supply app widgets to home screens.
As far as I know, this is NOT possible. You can only launch the new activity, but you have no control of it.
EDIT: Some devices offer this possibility using Cornerstone or similar frameworks, but I haven't seen an option for developers to use this for their own apps.

Sony SmartWatch widget only or widget and control extension?

As part of the free SmartWatch promotion I got a watch from Sony and have published an app for it. It is called SoundCheck and is found through the LiveWare Manager on the Google Play Market. A customer recently sent email for support. They installed Sound Check but did not see it on the watch since widgets are not enabled by default when they are installed. Is there any way to programmatically enable a widget when an app is installed? It might be nice for users if the widget was enabled by default rather than force them to navigate through the LiveWare manager to find the setting. This would be quite helpful for "widget-only" apps like Sound Check that do not have a control extension.
This week I created a pro version of my SmartWatch app to actually change the values displayed by the widget. Is it possible to open a control extension from a widget extension? Here is the use case. Short taps navigate through different screens of the widget. I want to use the long tap event type on the widget to open the 'editing' function in the control extension. Is this possible?
Thanks in advance for your help with these questions.
The question of how to enable a widget programmatically is still open. Here is code to open the control from a widget. This answer helped:
How should I do to start SmartWatch Extension from the program code?
if (type == Widget.Intents.EVENT_TYPE_SHORT_TAP) {
updateWidget();
} else {
//this code will launch the control and allow the user to change volume settings?
Intent intent = new Intent(Control.Intents.CONTROL_START_REQUEST_INTENT);
intent.putExtra(Control.Intents.EXTRA_AEA_PACKAGE_NAME, "com.mezcode.soundcheckpro");
intent.setPackage(mHostAppPackageName);
mContext.sendBroadcast(intent, Registration.HOSTAPP_PERMISSION);
}

Keypress event listener for android dialler

Can someone give me a tip on how to capture the values presses on the android dial pad? I think i should use a broadcast receiver for it
Are you trying to capture the values for a dialler related app? If you are, you can just capture the whole dialled string (ON_NEW_OUTGOING_CALL event) using getResultData(). If this returns null, you can then use intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER).
From memory you need the PROCESS_OUTGOING_CALL permission, and possibly some others, set in your manifest.
At this point, if you want to do anything with the number, you can modify the string and then just setResultData(newNumberString);
The only adendum at this point is that setResultData doesn't work with phones using the sense interface. With those, you actually need to start a new intent to be able to dial(until HTC finally open up their dev website..)

Categories

Resources