2017-05-08 15 views
-3

heres my code "on"と入力するとアクティビティ結果が表示されません。 onActivityResultにはポップアップがありません。アンドロイドスタジオでonactivityresultが表示されない

heres my code私が "on"と入力したときの活動結果を表示できません。 onActivityResultにはポップアップがありません。

heres my code私が "on"と入力したときの活動結果を表示できません。 onActivityResultにはポップアップがありません。

package com.ssss.myapplication; 

import android.content.Intent; 
import android.graphics.drawable.Drawable; 
import android.net.Uri; 
import android.provider.MediaStore; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.ImageView; 

import java.io.File; 

import static android.R.attr.data; 

public class MainActivity extends AppCompatActivity { 

    Button button; 
    ImageView imageView; 
    static final int CAM_REQUEST = 1; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     button = (Button) findViewById(R.id.button); 
     imageView = (ImageView) findViewById(R.id.image_view); 
     button.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
       File file = getFile(); 
       camera_intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); 
       startActivityForResult(camera_intent,CAM_REQUEST); 

      } 
     }); 

    } 

    private File getFile() { 
     File folder = new File("sdcard/camera_app"); 

     if (!folder.exists()) { 
      folder.mkdir(); 

     } 
     File image_file = new File(folder, "hiapp_image.jpg"); 

     return image_file; 



    } 
} 

答えて

1

は、ユーザーが、その後の活動とリターンで行われた場合

、システムはあなたの活動のonActivityResult()メソッドを呼び出して結果を受け取ります。このメソッドには、3つの引数が含まれます。

startActivityForResult()に渡したリクエストコード。 2番目のアクティビティーで指定された結果コード。これは、操作が成功した場合はRESULT_OK、ユーザーがバックアウトした場合、または何らかの理由で操作が失敗した場合はRESULT_CANCELEDです。 結果データを運ぶインテント。

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent 
data) 
{ 
    // Do something with the contact here (bigger example below) 
} 
関連する問題