我希望把額外的數據到一個Intent攝像頭,這似乎很簡單...相機意圖ACTION_IMAGE_CAPTURE,並把額外的數據
這是工作前一些日子,但我做了很多的代碼,AVD的變化和目標版本,現在它不工作。
該項目現在是在目標版本11.
其實我的目標是從我的數據庫通過一個ID來構建圖像的名字,但在這裏簡單的代碼來說明我的問題。
這裏的示例代碼:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".CameraTestActivity" >
<Button
android:id="@+id/buttonpic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:text="Button" />
</RelativeLayout>
-
public class CameraTestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_test);
Button buttonpic = (Button)findViewById(R.id.buttonpic);
buttonpic.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
///first try to put extra data
cameraIntent.putExtra("thisone", "ArgumentFrom");
///second try to put extra data
Bundle extras = new Bundle();
extras.putBoolean("thisalso",true);
cameraIntent.putExtras(extras);
///start camera activty with ID
startActivityForResult(cameraIntent, 1888);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
///if pic is picked and Intent ID is Camera one i.e. 1888
if (requestCode == 1888 && resultCode == RESULT_OK) {
///first try >> Not working
Bundle extra = getIntent().getExtras();////
if (extra != null) {
Log.d("extra: ","isnotnull");
Boolean inputThatIwant = extra.containsKey("thisone");
Boolean inputThatIwantBool = extra.containsKey("thisalso");
Log.d("thisone",inputThatIwant.toString());
Log.d("thisalso",inputThatIwantBool.toString());
}
///Second try >> Some Data is back (pic data... ?)
Bundle extras = data.getExtras();
if (extras != null) {
Log.d("extras: ","isnotnull"); /////-->>Print "isnotnull"
Boolean inputThatIwant = extras.containsKey("thisone");
Boolean inputThatIwantBool = extras.containsKey("thisalso");
Log.d("thisone",inputThatIwant.toString()); /////-->>Print "false"
Log.d("thisalso",inputThatIwantBool.toString()); /////-->>Print "false"
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.camera_test, menu);
return true;
}
}
[編輯] 我這裏怎麼處理這次終於,它可以幫助別人或許......
我只是在同一班級「分享」我的ID:
private String inputid;
當它是由相機的要求叫我填寫inputid字符串,顯然對這個OnresultActivity字符串不能爲空的ID,所以它的工作原理就這麼簡單......
但如果有人有更好的解決辦法,我會採取它!
祺....
你期待什麼'Intent'返回 - 它看起來不像你可以只是把任意extras放到你發送到'Camera Activity'的'Intent'中。看看官方文檔:http://developer.android.com/guide/topics/media/camera.html#intent-image – Darwind
謝謝你的回覆。我想你是對的。我找到了解決方法,現在我唱歌MediaStore.Images.Media.DESCRIPTION將數據傳遞給onactivityresult,它是專用於攝像頭參數的輸入android對象之一。但如果有更好的解決方案,我會感興趣... – neuronsoverflow