The application crashes when you try to set a wallpaper as the background of activity

advertisements

I have a problem where my application crashes when attempting to set the activity theme to the default wallpaper. I do not know what is causing this as I am new to Android. Help is appreciated!

AndroidManifest.xml

 <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <uses-feature android:name="android.hardware.telephony"/>

        <activity android:name=".WelcomeActivity" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        <activity
            android:name=".Launcher"
            android:theme="@style/Wallpaper" > <!-- HERE IT IS -->
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
        </activity>

    </application>

style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@android:color/transparent</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
<!--HERE IT IS -->
<style name="Wallpaper" parent="@android:style/Theme.Wallpaper"></style>

Java

package com.visualartsinternational.www.artui;

import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class Launcher extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launcher);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window w = getWindow(); // in Activity's onCreate() for instance
            w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }
    }

}


Set Wallpaper

 WallpaperManager wallpaperManager = WallpaperManager.getInstance(DetailActivity.this);
                                    try {
                                        wallpaperManager.setBitmap("Add your image");

                                        wallpaperManager.suggestDesiredDimensions(width, height);
                                        Toast.makeText(DetailActivity.this, "Wallpaper Set", Toast.LENGTH_SHORT).show();

                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }

Manifest add permission in manifest file

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