簡體   English   中英

多種設備上的Android壁紙

[英]Android wallpaper on multiple devices

我想從畫廊設置牆紙。 選定的圖像將必須使用設備的CropImage類。

問題在於每個設備都有一個不同的CropImage類,因此當我使用“ Crop”操作時,設備的CropImage會打開,但不會全部設置為牆紙。

碼:

Intent cropperIntent = new Intent("com.android.camera.action.CROP", chosenImageUri);
        cropperIntent.setDataAndType(chosenImageUri, "image/*");

        cropperIntent.putExtra("crop", true);
        cropperIntent.putExtra("aspectX", outSize.x);
        cropperIntent.putExtra("aspectY", outSize.y);
        cropperIntent.putExtra("outputX", outSize.x);
        cropperIntent.putExtra("outputY", outSize.y);
        cropperIntent.putExtra("width", outSize.x);
        cropperIntent.putExtra("height", outSize.y);
        cropperIntent.putExtra("scale", true);
        cropperIntent.putExtra("noFaceDetection", true);
        cropperIntent.putExtra("set-as-wallpaper", true); // for: com.android.gallery3d.app.CropImage
        cropperIntent.putExtra("setWallpaper", true); // for: com.android.camera.CropImage

對於某些設備,它根本不設置為牆紙(如HTC)。 可能還需要設置其他一些內容,例如“設置為牆紙”和“設置為牆紙” ...

是否有通用方法為所有設備設置帶有裁切器的牆紙?

在某些手機(例如HTC)上,這勢必不起作用,因為它們使用自己的圖庫/相機。 對於這些設備,您可以僅使用未裁剪的圖像作為單獨的資源。 但是,如果您具有圖像的位圖,則將添加此功能以設置為牆紙:

  public void SetBackground(int Url) {

    try {
        File file = new File("/sdcard/sampleimage");
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), Url);
        bitmap.compress(CompressFormat.JPEG, 80, new FileOutputStream(file));
        Context context = this.getBaseContext();
        context.setWallpaper(bitmap);            
        Toast.makeText(getApplicationContext(), "Wallpaper has been set",             Toast.LENGTH_SHORT).show();            
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }         
}

您應該為此添加權限

<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>

這是從這里拿來的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM