4

これは私のアプリの外観です:

ここに画像の説明を入力

これは私がボタンクリックで実行したいことです:別のアプリで画像を開く

ここに画像の説明を入力

これは私が試したものです:

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 で画像を表示している非常に単純なアプリを作成しました。ボタンをクリックすると、この画像を別のアプリで開きたいと思います。

4

2 に答える 2

3

次のコードを使用してみてください..

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);
于 2014-07-27T04:26:16.337 に答える