2016-06-22 1 views
0

Je suis en mesure de changer le fond d'écran de l'appareil, mais je veux un utilisateur à l'option gibe lorsque vous cliquez sur le bouton fond d'écran, soit il veut définir l'image comme écran d'accueil ou pour WhatsApp.Définir comme papier peint

ici est ma méthode de travail pour la mise en fond d'écran:

fullImageView = (ImageView) findViewById(R.id.imgFullscreen); 

public void setAsWallpaper(Bitmap bitmap) { 
     try { 
      WallpaperManager wm = WallpaperManager.getInstance(_context); 

      wm.setBitmap(bitmap); 
      Toast.makeText(_context, 
        _context.getString(R.string.toast_wallpaper_set), 
        Toast.LENGTH_SHORT).show(); 
     } catch (Exception e) { 
      e.printStackTrace(); 
      Toast.makeText(_context, 
        _context.getString(R.string.toast_wallpaper_set_failed), 
        Toast.LENGTH_SHORT).show(); 
     } 
    } 

et ce code de clic méthode:

public void onClick(View v) { 
     Bitmap bitmap = ((BitmapDrawable) fullImageView.getDrawable()) 
       .getBitmap(); 

     switch (v.getId()) { 
     // button Download Wallpaper tapped 
     case R.id.llDownloadWallpaper: 
      utils.saveImageToSDCard(bitmap); 
      break; 
     // button Set As Wallpaper tapped 
     case R.id.llSetWallpaper: 

      utils.setAsWallpaper(bitmap); 
      break; 
     default: 
      break; 
     } 

    } 

Code de travail serait très utile.

Répondre

0
private void setImageAsWallpaperPicker(Uri path) { 
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); 
    intent.setType("image/*"); 
    MimeTypeMap map = MimeTypeMap.getSingleton(); 
    String mimeType = map.getMimeTypeFromExtension("png"); 
    intent.setDataAndType(path, mimeType); 
    intent.putExtra("mimeType", mimeType); 
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    startActivity(Intent.createChooser(intent, "Set as")); 
} 
+0

Ai-je besoin de remplacer mon code existant de cette ..Je suis nouveau android –

+0

oui, si vous voulez faire apparaître un pop-up et sélectionnez ce que vous voulez faire avec le chemin, comme comme fond d'écran, ou définir comme profil whatsapp, etc. –