2010-08-05 3 views
1

Possible en double:
Android - how to set the wallpaper imageComment mettre en fond d'écran dans Android?

Je VHA commencé à faire application dans Android. Je veux définir wallpaer dans Android qui fonctionne en arrière-plan (en utilisant le service) et le fond d'écran va changer dans les 5 minutes en arrière-plan. Je garde les fichiers image dans Drawable. N'importe qui envoie le code pour placer le wallpaer et le reprendre après 5 minutes.

Merci à l'avance.

Répondre

6

Here is an example. Mais malheureusement ça ne marche pas pour moi. Fondamentalement, je suis en utilisant le code suivant:

code:

WallpaperManager myWallpaperManager = WallpaperManager 
      .getInstance(this); 
    String imageFilePath = getFilePath(imageUri); 
    Bitmap myBitmap = BitmapFactory.decodeFile(imageFilePath); 
    if (myBitmap != null) { 
     try { 
      myWallpaperManager.setBitmap(myBitmap); 
     } catch (IOException e) { 
      showToast(ImageDisplay.this, 
        "Failed to set Backgroundimage"); 
     } 
    } else { 
     showToast(ImageDisplay.this, "Failed to decode image."); 
    } 

Le imageFilePath est correct pour autant que je peux dire (comme je l'ai aussi pour différentes choses qui fonctionne). Il n'y a pas d'erreur ou d'exception. L'arrière-plan de mon téléphone est juste vide après avoir appelé cette application. Qu'est-ce que je fais mal?

0

Vous pouvez regarder le WallpaperManager.
Écrivez un service simple et vous pouvez utiliser un Timer pour changer le papier peint à intervalles réguliers.

+0

Je suis incapable de le faire en suivant WallpaperManager. S'il vous plaît aidez-moi .......... – Subrat

+0

Il serait utile si vous pourriez expliquer pourquoi vous ne pouvez pas utiliser WallpaperManager. Quel niveau d'API ciblez-vous? – codinguser

2
is = new FileInputStream(new File(imagePath)); 
bis = new BufferedInputStream(is); 
Bitmap bitmap = BitmapFactory.decodeStream(bis); 
Bitmap useThisBitmap = Bitmap.createScaledBitmap(
bitmap, parent.getWidth(), parent.getHeight(), true); 
bitmap.recycle(); 
if(imagePath!=null){ 
    System.out.println("Hi I am try to open Bit map"); 
wallpaperManager = WallpaperManager.getInstance(this); 
wallpaperDrawable = wallpaperManager.getDrawable(); 
wallpaperManager.setBitmap(useThisBitmap); 

........................................... ...... si vous avez l'URI d'image alors utilisez ceci

wallpaperManager = WallpaperManager.getInstance(this); 
wallpaperDrawable = wallpaperManager.getDrawable(); 
mImageView.setImageURI(imagepath); 

.............. Informez-moi s'il y a un problème.

Questions connexes