4

this is how my app look:

enter image description here

this is what i want to perform on button click: open image in another app

enter image description here

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.

user3739970
  • 591
  • 2
  • 13
  • 28

2 Answers2

3

Try using the following Code..

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);
Umer Kiani
  • 3,783
  • 5
  • 36
  • 63
  • how do i pass image-view image to uri – user3739970 Jul 27 '14 at 07:17
  • You cannot pass imageview. if you want to show the image in your own app then you can use imageview to show the image inside your own app. – Umer Kiani Jul 27 '14 at 07:18
  • `intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");` in this line it gets image from sd card location, but is there a way to get image source from drawable or get the image that is showing in imageview – user3739970 Jul 27 '14 at 07:22
  • Ok now i Get it yes there is a way. will edit question. – Umer Kiani Jul 27 '14 at 07:23
  • To Open Image in Drawable you will have to do something like Uri uri = Uri.parse("android.resource://your.package.here/drawable/image_name"); hope this helps :) now awaiting you to accept answer :) – Umer Kiani Jul 27 '14 at 07:29
  • according to your code i tried this `intent.setDataAndType(Uri.parse("android.resource://package com.example.wallpaper_test;/drawable/pop"), "image/*");` and got error unfortunately stopped – user3739970 Jul 27 '14 at 07:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/58092/discussion-between-umer-kiani-and-user3739970). – Umer Kiani Jul 27 '14 at 07:36
2

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:"));
                    //
user3739970
  • 591
  • 2
  • 13
  • 28