2017-07-19 82 views
0

我有:相機意圖後有新的活動

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_foto); 

    Intent intentFotocamera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); //creo un timestamp univoco 

    File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MyImages"); 
    imagesFolder.mkdirs(); //creo un nuovo album 

    File image = new File(imagesFolder, "QR_" + timeStamp + ".png"); //concateno 
    Uri uriSavedImage = Uri.fromFile(image); 

    intentFotocamera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); 
    startActivityForResult(intentFotocamera, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); 
} 

現在,當用戶按下照片確認按鈕(然後保存在本地),我想創建一個新的活動,因爲我想打印照片在我的應用程序。

如何創建新的活動?

+0

看到這個[相機活動教程(https://www.androidhive.info/2013/09/android-working-with-camera-api/) – Lal

回答

2

在override方法onActivityResult()中啓動新的活動。

https://developer.android.com/training/basics/intents/result.html

例子:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent 
data) { 
// Check which request we're responding to 
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { 
    // Make sure the request was successful 
    if (resultCode == RESULT_OK) { 
     // The user picked a contact. 
     // The Intent's data Uri identifies which contact was selected. 

     // Do something with the contact here (bigger example below) 
    } 
} 
} 
+0

什麼是'PICK_CONTACT_REQUEST'? – Lal

+1

他應該接受'CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE'這個答案。 –

+0

我剛剛使用谷歌的例子,忘記編輯該部分。 https://developer.android.com/training/basics/intents/result.html – MrBovineJoni

1

是否要打開新的活動,並顯示其最近拍攝的照片?

這裏是你如何做到這一點。

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    try { 
     super.onActivityResult(requestCode, resultCode, data); 

     if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { 

        "handle here" 

     } 
    } catch (Exception ex) { 

    } 

} 
+0

這不是一個答案!評論應發佈在評論部分 –