这是我的应用程序的外观:
这就是我想要在按钮单击时执行的操作:在另一个应用程序中打开图像
这是我尝试过的:
package com.example.wallpaper_test;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class WallpaperScreenActivity extends ActionBarActivity {
public static final int REQUEST_CODE = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.wallpaper_layout);
// image resource
ImageView img = (ImageView) findViewById(R.id.imageView1);
img.setImageResource(R.drawable.pop);
// call installed wallpaper app to set wallpaper on button click
Button b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View vx) {
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(uri.setreso, "image/jpeg");
intent.putExtra("mimeType", "image/jpeg");
this.startActivity(Intent.createChooser(intent, "Set as:"));
}
});
}
}
我得到的那些错误:
Description Resource Path Location Type
uri cannot be resolved to a variable WallpaperScreenActivity.java /Wallpaper_Test/src/com/example/wallpaper_test line 32 Java Problem
The method startActivity(Intent) is undefined for the type new View.OnClickListener(){} WallpaperScreenActivity.java /Wallpaper_Test/src/com/example/wallpaper_test line 34 Java Problem
我创建了一个非常简单的应用程序,其中我在 image_view 中显示图像,并且我想在按钮单击时在另一个应用程序中打开此图像。