5

I have developed a live wallpaper app and it is accessible only from Google's Live wallpaper app, but there are phones like Xiaomi, Oppo which has their own wallpaper app and My app doesn't show in their wallpaper section. Can anyone help me fix this problem or redirect me to an idea to fix this?

This is My Wallpaper.xml file

<?xml version="1.0" encoding="UTF-8"?>    
<wallpaper
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:description="@string/wallpaper_description"
        android:thumbnail="@raw/element1"
        android:settingsActivity=""/>

This is My Manifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.edustan.mywallpaper">
<uses-feature
    android:name="android.software.live_wallpaper"
    android:required="true" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
<uses-permission android:name="android.permission.SET_WALLPAPER"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:ignore="AllowBackup,GoogleAppIndexingWarning" >
    <service
        android:name=".MyWallpaperService"
        android:enabled="true"
        android:label="Wallpaper Example "
        android:permission="android.permission.BIND_WALLPAPER">
        <intent-filter>
            <action android:name="android.service.wallpaper.WallpaperService" />
        </intent-filter>

        <meta-data
            android:name="android.service.wallpaper"
            android:resource="@xml/wallpaper" />
    </service>
</application>

This is My WallpaperService class file

 @Override
public Engine onCreateEngine() {

    return new MyWallpaperEngine();
}
private class MyWallpaperEngine extends Engine{
    public Bitmap image1, image2, image3;
    private int count_new =0;
    private int previous_count=0;
    SharedPreferences pref = context.getSharedPreferences("MyPref", 0);
    Editor editor = pref.edit();
    private Handler handler = new Handler();
    int height=1920,width=1080;
    boolean first_time = pref.getBoolean("first",true);
    boolean second_time = pref.getBoolean("second",true);
    public  MyWallpaperEngine(){
        Log.d("wallyt","Unlocked");
        image1 = BitmapFactory.decodeResource(getResources(), R.raw.element1);
    }

    @Override
    public void onCreate(SurfaceHolder surfaceHolder) {
        super.onCreate(surfaceHolder);
        if(!isPreview()) {
            ScreenOffReceiver screenOffReceiver = new ScreenOffReceiver();
            registerReceiver(screenOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
            Log.d("wallyt", "OnCreate Called");
            count_new = pref.getInt(COUNT_KEY,0);
        }
        else{
            count_new = previous_count;

        }


    }

    @Override
    public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        super.onSurfaceChanged(holder, format, width, height);
        width=width;
        height=height;

    }

    public void onOffsetsChanged(float xOffset, float yOffset, float xStep, float yStep, int xPixels, int yPixels)
    {
        Log.d("Wallytab",xOffset + " "+yOffset+" " + xStep+ " "+ yStep + " "+ xPixels+ " "+yPixels);

        float x = pref.getFloat("xpixels",xPixels);


        editor.putFloat("xpixels",xPixels);
        editor.apply();
        if(x==xPixels&&(count_new==0||count_new>previous_count)) {
            drawFrame();
            previous_count=count_new;
        }


    }



    void drawFrame()
    {
        Log.d("wallyt","drawFrame Called");

        final SurfaceHolder holder = getSurfaceHolder();

        Canvas c = null;
        int n = pref.getInt(COUNT_KEY,0)+1;

        try
        {
            c = holder.lockCanvas();

            if (c != null)
            {

                try {
                    Log.i("wallyt", "Wallpaper Change open");
                    Bitmap overlay= BitmapFactory.decodeResource(context.getResources(),img[(n) % 120]);

                   // Bitmap bg = BitmapFactory.decodeResource(context.getResources(), R.raw.white);
                    Bitmap bg = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                    bg.eraseColor(Color.WHITE);
                    int bitmap1Width = bg.getWidth();
                    int bitmap1Height = bg.getHeight();
                    int bitmap2Width = overlay.getWidth();
                    int bitmap2Height = overlay.getHeight();
                    float marginLeft = (float) (bitmap1Width * 0.5 - bitmap2Width * 0.5);
                    float marginTop = (float) (bitmap1Height * 0.5 - bitmap2Height * 0.5);
                    int width = Resources.getSystem().getDisplayMetrics().widthPixels;
                    int height = Resources.getSystem().getDisplayMetrics().heightPixels;
                    Rect screenBounds = new Rect(0,0,width,height);
                    Bitmap finalBitmap = Bitmap.createBitmap(bitmap1Width, bitmap1Height, bg.getConfig());
                    Canvas canvas = new Canvas(finalBitmap);
                    canvas.drawBitmap(bg, new Matrix(), null);
                    canvas.drawBitmap(overlay, marginLeft, marginTop, null);


                    c.drawBitmap(finalBitmap, null, screenBounds, null);
                    editor.putInt(COUNT_KEY,n+1);
                    editor.putBoolean("first",false);
                    editor.apply();
                    Log.d("wallyt","count"+n);

                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    Log.d("Wally",e.getMessage());
                }
            }
        } finally
        {
            if (c != null) holder.unlockCanvasAndPost(c);
        }
    }
Gokula Krishnan
  • 319
  • 2
  • 5

0 Answers0