如何在Android的永久设置壁纸 [英] How to set wallpaper permanently in android

查看:135
本文介绍了如何在Android的永久设置壁纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的应用程序可以设置图像为墙纸。我使用以下code固定在每一个屏幕图像。在code是工作的罚款。图像适应正常。但我有一个问题,如果我玩任何游戏,然后返回到主屏幕或重新启动设备,然后壁纸变焦的大小。我想阻止这一切。我想图像大小适合,因为它是当我设置从我的Andr​​oid应用程序的墙纸第一次。

I am creating app to set image as wallpaper. I am using following code to fix image in every screen. The code is working fine. Image fit properly. But I have one problem if I play any game and then back to home screen or I restart my device then size of wallpaper zoom. I want to stop this. I want image size fit as it is on first time when I set wallpaper from my android app.

下面是code -

Here's Code-

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.full_image);
        face = Typeface.createFromAsset(getAssets(), "fonts/ABEAKRG.TTF");
        Intent i = getIntent();
        position = i.getExtras().getInt("id");        
        full = (LinearLayout) findViewById(R.id.full);
        btn = (Button)findViewById(R.id.btn);
        btn.setTypeface(face);
        btn.setOnClickListener(new Button.OnClickListener(){
        @Override
        public void onClick(View arg0) { 
             DisplayMetrics metrics = new DisplayMetrics(); 
             getWindowManager().getDefaultDisplay().getMetrics(metrics);
             int height = metrics.heightPixels; 
             int width = metrics.widthPixels;
             Bitmap tempbitMap = BitmapFactory.decodeResource(getResources(), mThumbId[position]);
             Bitmap bitmap = Bitmap.createScaledBitmap(tempbitMap,width,height, true);
             WallpaperManager wallpaperManager = WallpaperManager.getInstance(FullImageActivity.this); 
             wallpaperManager.setWallpaperOffsetSteps(1, 1);
             wallpaperManager.suggestDesiredDimensions(width, height);
             try {
               wallpaperManager.setBitmap(bitmap);
               Toast.makeText(getApplicationContext(), "Done", Toast.LENGTH_SHORT).show();
               } catch (IOException e) {
               e.printStackTrace();
             }
        }});
        changeBackground();
        ActivitySwipeDetector activitySwipeDetector = new ActivitySwipeDetector(this);
        full.setOnTouchListener(activitySwipeDetector);
    }



    private void changeBackground(){
        full.setBackgroundResource(mThumbId[position]);
   }

先谢谢了。

推荐答案

下面是code段为工作

Here is the code segment working for that

该MainActivity.java code

The MainActivity.java Code

该BootReceiver.java对于开机后设置壁纸完成.. code

The BootReceiver.java For Setting Wallpaper after boot completed..Code

和的Manifest.xml有关设置权限.. code

And The Manifest.xml For setting Permissions..Code

感谢

这篇关于如何在Android的永久设置壁纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆