I was trying to set the default wallpaper by using a button but for some reason when i set the InputStream in the OnCreate Method, i get this error "expected resource of type raw". I am referencing the drawable folder and using the icon.png image which is in the drawable folder. I was following the tutorials in the NewBoston Series and it seems to work fine for Travis but for some reason mine doesnt work in Android Studio. What could be the error? Thanks
Camera.java:
package com.example.user.cameraapplication;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Switch;
import java.io.IOException;
import java.io.InputStream;
/**
* Created by user on 16-08-2015.
*/
public class Camera extends Activity implements View.OnClickListener{
ImageView iv;
Button b1,b2;
ImageButton img;
Intent i;
final static int cameractivity = 0;
Bitmap b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.photo);
inititalize();
InputStream is = getResources().openRawResource(R.drawable.icon);
b = BitmapFactory.decodeStream(is);
}
private void inititalize() {
iv = (ImageView)findViewById(R.id.iView1);
img = (ImageButton)findViewById(R.id.imgbtn);
b1 = (Button)findViewById(R.id.btn1);
b2 = (Button)findViewById(R.id.btn2);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.btn1:
try {
getApplicationContext().setWallpaper(b);
} catch (IOException e) {
e.printStackTrace();
}
break;
case R.id.imgbtn:
i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,cameractivity);
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK)
{
Bundle extras = data.getExtras();
b = (Bitmap)extras.get("data");
iv.setImageBitmap(b);
}
}
}
Image: