Wallpaper is not setting up once set one wallpaper - android

I have a video wallpaper app in which I am trying to set the live wallpaper for the first time it works fine. But the second time it does not change the wallpaper unless I restart the device.
I tried using "wallpapermanager.clear" function as well but the problem with that is if the user doesn't set the wallpaper the previous wallpaper gets removed automatically.
I don't want the previous one to get removed.
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
vintent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
new ComponentName(this, MyWallpaperService.class));
vstartActivity(intent);
try {
WallpaperManager.getInstance(this).clear();
} catch (IOException e) {
e.printStackTrace();
}

Related

how to clear app data programmatically

Based on the notification title which says "you have been logged out", I want to trigger clear app data event in android. I browsed a lot. didn't get what I needed. can someone help?
The Simplest way to do this is
private void deleteAppData() {
try {
// clearing app data
String packageName = getApplicationContext().getPackageName();
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm clear "+packageName);
} catch (Exception e) {
e.printStackTrace();
} }
This will clear the data and remove your app from memory. It is equivalent to clear data option under Settings --> Application Manager --> Your App --> Clear data
As an alternate I have one more option i.e. ((ActivityManager)context.getSystemService(ACTIVITY_SERVICE)‌​) .clearApplicationUserData();
But it has a limitation that it only work API level >=19

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.!

Looking for an example of the new Android API setMediaButtonReceiver

Currently I am using
mAudioManager.registerMediaButtonEventReceiver(mRemoteControlResponder);
but this is now deprecated in 5.0 and replaced by setMediaButtonReceiver. There are 5 links in Google all pointing to developer.android.com.
Has anyone used this yet? If so can you provide an example?
Check this page: http://grepcode.com/file/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-0/android/media/session/MediaSession.java It is a rather large example of the complete flow.Here one of the most relevant parts
Set a pending intent for your media button receiver to allow restarting playback after the session has been stopped. If your app is started in this way an android.content.Intent.ACTION_MEDIA_BUTTON intent will be sent via the pending intent.
Parameters: nullmbr The android.app.PendingIntent to send the media button event to.
public void More ...setMediaButtonReceiver(#Nullable PendingIntent mbr) {
try {
mBinder.setMediaButtonReceiver(mbr);
} catch (RemoteException e) {
Log.wtf(TAG, "Failure in setMediaButtonReceiver.", e);
}
}

Change background color has no effect once screen has been rotated

all I am new to Android and now I am facing a strange problem, the problem in short is
"Receive TCP message and then change background color of GUI has no effect once screen has been rotated."
What I want to archive:
Have a APP running on Android device, connect to a PC via TCP.
PC can send a string to APP, the APP will then do something base on string received.
In this case a string, "change back ground color to red(with phone vibrates)/black" is send to APP via TCP, so Android user will see a blinding effect with vibration.
What is the problem:
I can archive what I want. But once the screen has been rotated, the color cannot be changed, only vibration remain.
What I had tried:
I put a button on the APP which will manually trigger color change event(with vibration). It works fine even if I rotate the screen.
Further test shows that UI operation such as change background color and animation triggered by TCP read are vanished, however ringtone and vibration remain unchanged.
I upload a video to Youtube http://youtu.be/n0gxXzzf-bo
Below are java code ,the button and TCP call same method: ChangeColor()
public void ChangeColor(){
Thread t= new Thread(new ChangeColorTest());
t.start();
}
public class ChangeColorTest implements Runnable{
public void run() {
try {
for(int i=0;i<3;i++){
mBlinkHandler.sendEmptyMessageDelayed(1, 0);
Thread.sleep(300);
mBlinkHandler.sendEmptyMessageDelayed(2, 0);
Thread.sleep(300);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Handler mBlinkHandler = new Handler(){
#Override
public void handleMessage(Message msg){
super.handleMessage(msg);
// mScreen = (LinearLayout)findViewById(R.id.mylinerlayout);
if(msg.what==1){
mScreen.setBackgroundColor(Color.RED);
Vibratoration();
}else if(msg.what==2){
mScreen.setBackgroundColor(Color.BLACK);
}
}
};
What I want to know?
If someone could possible figure out a solution, it would be much appreciated.
What is my platform?
Server PC: Win7 64bits VS2010 C#
Android platform: 4.0 Samsung S2
Development IDE:Motodev
SDK API: Android 3
One solution would be to lock the screen so it can't be rotated? (Or at least lock it during this functionality.)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Android will recreate the whole activity when you rotate the screen - so probably your variable "mScreen" won't point to the instance actually visible on the screen after rotation.
You can avoid, that android recreates the activity as explained here:
http://developer.android.com/guide/topics/resources/runtime-changes.html

Weird Samsung Galaxy S camera preview

I am using pretty much the same code as the Camera app code from Google but am getting really weird results. Inside my application and the Camera app from Google the preview gets stuck or is overlid with weird lines. The preview is usually the last thing which I see in the phone's own Camera app.
The Samsung model is I9003. The same code ran fine on I9000 which Samsung just discontinued. The code also works fine on an HTC Wildfire.
Any resolution for this?
Just noticed that after taking a photo inside my application the camera preview becomes normal. Same thing is happening in the Google camera application.
Couldn't post the answer earlier. Wasn't sure if it was the right thing to do, but now with the app running properly on around 150 devices I guess this works.
So the Android camera app in its onCreate function had the following code:
/*
* To reduce startup time, we start the preview in another thread.
* We make sure the preview is started at the end of onCreate.
*/
Thread startPreviewThread = new Thread(new Runnable() {
public void run() {
try {
mStartPreviewFail = false;
startPreview();
} catch (CameraHardwareException e) {
// In eng build, we throw the exception so that test tool
// can detect it and report it
if ("eng".equals(Build.TYPE)) {
throw new RuntimeException(e);
}
mStartPreviewFail = true;
}
}
});
startPreviewThread.start();
For some reason this did not work on GT-I9003. What I noticed was that after taking a photo the preview would come properly so there was nothing wrong with the hardware as such. I tried to retrace what was happening after a photo was taken and then compare it with the code with which the camera was first initialized. I commented out this code from onCreate. The onResume from the camera app looked like this:
if (mSurfaceHolder != null) {
// If first time initialization is not finished, put it in the
// message queue.
if (!mFirstTimeInitialized) {
mHandler.sendEmptyMessage(FIRST_TIME_INIT);
} else {
initializeSecondTime();
}
}
I changed this to:
if (!mFirstTimeInitialized) {
initializeFirstTime();
} else {
initializeSecondTime();
}
There were some other changes too, will put it up on GitHub as a separate app soon.

Categories

Resources