Set Live Wallpaper Programmatically on Rooted Device Android - android

Is it possible somehow to set Live Wallpaper programmatically using my Application?
I am working on an Application that her purpose is to choose some of the Installed Live Wallpapers on the device and to set it as a Live Wallpaper. This action need to be completed via my Application.
As I was researching I found some answers that this can be done with rooting the Android Device?
Can some one help me out how to do that exactly?

Android OS prior to Jelly Bean does not allow you to programatically set a live wallpaper.
For now Jelly Bean supports changing the Live Wallpaper programtically without user interaction

Sorry to break it to the nay sayers but it is possible to set a live wallpaper programmatically WITHOUT user interaction. It requires:
Your app to be system-privileged
<uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />
Java reflection (super hacking code)
A class reference to the desired WallpaperService (live Wallpaper)
NOTE: For item #3, I used my own live wallpaper, MyWallpaperService class
This can only be done if your app is system-privileged and has this permission in the manifest:
<uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />
Now, using reflection, you can call the hidden methods of WallpaperManager to manually set the live wallpaper:
WallpaperManager manager = WallpaperManager.getInstance(context);
Method method = WallpaperManager.class.getMethod("getIWallpaperManager", null);
Object objIWallpaperManager = method.invoke(manager, null);
Class[] param = new Class[1];
param[0] = ComponentName.class;
method = objIWallpaperManager.getClass().getMethod("setWallpaperComponent", param);
//get the intent of the desired wallpaper service. Note: I created my own
//custom wallpaper service. You'll need a class reference and package
//of the desired live wallpaper
Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
intent.setClassName(context.getPackageName(), MyWallpaperService.class.getName());
//set the live wallpaper (throws security exception if you're not system-privileged app)
method.invoke(objIWallpaperManager, intent.getComponent());
Refer to the source code:
LiveWallpaperActivity
LiveWallpaperPreview

Related

Android API Level 16 and higher Torch App

I found this Question but it doesn't work for me. (Nothing happens. Tested on Wiko Rainbow Jam)
Android - Camera2 : The easiest way to turn on the torch light
My App have to run on min. API Level 16! Is there an SupportCameraManager or an Library (under Apache), which can I use?
You Can Use this.
Initialize the NoobCameraManager singleton.
NoobCameraManager.getInstance().init(this);
You can optionally set the Log Level for debug logging. Logging uses LumberJack library. The default LogLevel is LogLevel.None
NoobCameraManager.getInstance().init(this, LogLevel.Verbose);
After that you just need to call the singleton to turn on or off the camera flash.
NoobCameraManager.getInstance().turnOnFlash();
NoobCameraManager.getInstance().turnOffFlash();
You can take care of the runtime permission to access Camera yourself or can allow the library to do it for you
NoobCameraManager.getInstance().takePermissions();
Note: The library will take permissions, if you haven't already, even without calling takePermissions() explicitly. This behavior may change in future.
It's easy to toggle Flash too
NoobCameraManager.getInstance().toggleFlash();
It's a good practice to release all the resources, once you're done.
NoobCameraManager.getInstance().release();
SOLUTION: The problem was that I only got the camera's parameters when turning on the light and turning off the light. This must apparently also be done in the constructor or in the overwriting onStart method.
#Override
protected void onStart() {
super.onStart();
camera = Camera.open(); //Also Call this
params = camera.getParameters(); //and this, in the Constructor
}
as fields:
private Camera camera;
Parameters params;
And then you can start the flashlight with these snippets of code: Android - Camera2 : The easiest way to turn on the torch light

stop/start live wallpaper service

how can i stop and start live wallpaper service in android programmatically ?
this code help me to send user for select my live wallpaper from list
if (Build.VERSION.SDK_INT > 15)
{
i.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
String pkg = WallpaperService.class.getPackage().getName();
String cls = WallpaperService.class.getCanonicalName();
i.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(pkg, cls));
}
else
{
i.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
}
startActivityForResult(i, 0);
is there any way to programmatically change the user's live wallpaper ?
If your are using a test device that have API level below the 15 it will not be possible to change live wallpaper the way you want.! Your code is perfectly alright. Just test on a device that have API level greater then 15/16.!

Embed zxing barcode scanner to the activity

I'm writing android application and my client requires a barcode scanner in it. They are really specific about it, so the layout they want is like this:
If a qr code found - it jumps to another window automatically. If manual pressed - you are asked to type manually and proceed with the rest of the app.
So basically I could embed zxing code to my app and add it to the activity but I don't want that and would like to have it as a separate app.
What I have at the moment is a separate activity called like this:
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
I also tried this:
IntentIntegrator intentIntegrator = new IntentIntegrator(this);
Intent i = intentIntegrator.initiateCustomScan();
LocalActivityManager mgr = getLocalActivityManager();
Window w = mgr.startActivity("unique_per_activity_string", i);
View wd = w != null ? w.getDecorView() : null;
if(wd != null) {
scanButton.addView(wd);
}
But then I get java.lang.SecurityException:
03-19 12:22:55.890: E/AndroidRuntime(29394): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.menucard.barcode.scan/com.barcode.scan.ScanActivity}: java.lang.SecurityException: Requesting code from com.google.zxing.client.android (with uid 10139) to be run in process com.menucard.barcode.scan (with uid 10169)
Maybe someone has an idea how to add a separate app into my activity? Or other ways to accomplish this?
You can't embed an external app in another app via Intent unfortunately. The external app here needs to take over the whole screen, and is in landscape mode, for starters.
You should write your own app, but can reuse parts of Barcode Scanner in your app so that it's not entirely from scratch. Just please don't copy the AndroidManifest.xml file. I think it will also be clearly not confused with Barcode Scanner given the different UI. All that remains is to make sure you follow the terms of the Apache License (easy).
#MindaugasSvirskas, your last comment is exactly what I was about to post now:-) I have faced the same problem in the past, in several apps, and believe me, just make use of Intents, that's the way the whole Android system is designed, favouring intercommunication between apps. iOS programmers can easily integrate the scanning Zxing layout in their own layouts, but we are supposed to make use of intents, and I agree.

Android: Programmatically open "Recent Apps" dialog

I would like to be able to open the "Recent Apps" dialog from my application. This is the dialog that is opened by long-pressing the home button. I am programming for Android 4.1 or earlier. I found a way to do it by implementing a custom AccessibilityService and calling AccessibilityService.performGlobalAction(GLOBAL_ACTION_RECENTS), but this requires enabling accessibility on the phone, which is not very desirable. Is there any other way to open this dialog from an app?
Thanks for the help!
This code won't work on Nougat or later
It is possible to trigger the recent apps activity.
The StatusBarManagerService implements an public method which you can use through reflection.
You can use the following code:
Class serviceManagerClass = Class.forName("android.os.ServiceManager");
Method getService = serviceManagerClass.getMethod("getService", String.class);
IBinder retbinder = (IBinder) getService.invoke(serviceManagerClass, "statusbar");
Class statusBarClass = Class.forName(retbinder.getInterfaceDescriptor());
Object statusBarObject = statusBarClass.getClasses()[0].getMethod("asInterface", IBinder.class).invoke(null, new Object[] { retbinder });
Method clearAll = statusBarClass.getMethod("toggleRecentApps");
clearAll.setAccessible(true);
clearAll.invoke(statusBarObject);
Have fun
You cannot access that. However, it isn't super hard to roll your own. The getRecentTasks() method returns a list of recently run apps. Simply take the list and add your own UI to it.
One advantage to this is that the default one, at least on older versions of Android, only shows you about 8 apps. If you roll your own can show as many as you want.
This can be done using the TOGGLE_RECENTS Intent.
Intent intent = new Intent ("com.android.systemui.recent.action.TOGGLE_RECENTS");
intent.setComponent (new ComponentName ("com.android.systemui", "com.android.systemui.recent.RecentsActivity"));
startActivity (intent);
Note Package would be changed basis on Api level. See here.
Android 4.1: "com.android.internal.policy.impl.RecentApplicationsDialog"
Android 4.2 - 4.4: "com.android.systemui.recent.RecentsActivity"
Android 5.0 - 7.1: "com.android.systemui.recents.RecentsActivity" ("s" letter was added)

Accessing front camera of mobile using flash?

Recently I went thru the code for accessing the camera using flash ActionScript3 and I have tested the code in iMac machine, iPhone and Android.Now based on this, I am developing an application for Android which includes the accessibility of the front camera. Now my Problem is I dont know how to access the front camera? We should use some other code or should we specify which camera should be accessed? First of all, can we access the front camera thru flash?
I made a simple android app. Here is the code for selecting camera window
public class SelectCameraAlertAndroid extends StartAlertAndroid_design{
public function SelectCameraAlertAndroid() {
frontCameraButton.addEventListener(MouseEvent.CLICK, onFrontCamera);
backCameraButton.addEventListener(MouseEvent.CLICK, onBackCamera);
}
private function onFrontCamera(event:MouseEvent):void {
Model.model.camera = Camera.getCamera("1");
Model.model.cameraSelectedSignal.dispatch();
dispatchEvent(new Event("closeMe"));
}
private function onBackCamera(event:MouseEvent):void {
Model.model.camera = Camera.getCamera("0");
Model.model.cameraSelectedSignal.dispatch();
dispatchEvent(new Event("closeMe"));
}
}
Not true. You can access the front camera on Android.
The only problem is that you don't get to use the CameraUI(pretty sure).
var camera = Camera.getCamera("1");
camera.setMode(stage.stageWidth, stage.stageHeight, 30, true);
var video:Video = new Video(stage.stageWidth, stage.stageHeight);
video.attachCamera(camera);
addChild(video);
Note: This answer is outdated. Please refer to the other answers for updated information.
Currently, AIR only supports access to the primary camera on an Android device.
http://forums.adobe.com/thread/849983
Official documentation: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/Camera.html#getCamera()
"On Android devices, you can only access the rear-facing camera."

Categories

Resources