这是我的应用程序的外观:
这是我想要在按钮点击时执行的操作:在另一个应用程序中打开图像
这是我尝试过的:
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中显示一张图片,并希望在按下按钮时在另一个应用程序中打开此图片。
Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("android.resource://com.example.wallpaper_test/drawable/pop"),"image/*"); startActivity(intent);
但是遗憾的是,应用程序停止运行了。 - user3739970