Reputation: 591
this is how my app look:
this is what i want to perform on button click: open image in another app
this is what i tried:
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:"));
}
});
}
}
those errors i got:
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
i created a very simple app in which i am showing an image in image_view and i want to open this image in another app on button click.
Upvotes: 4
Views: 3399
Reputation: 591
first i saved image to sd card then open it using this below code
// open image in another app
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(Uri.parse("file://mnt/sdcard/temp_image0.png"),"image/*");
intent.putExtra("mimeType", "image/*");
startActivity(Intent.createChooser(intent, "Set as:"));
//
Upvotes: 2