मेरे ऐप में मैं गैलरी से छवियों को प्रदर्शित नहीं कर रहा हूं, जहां से मैं एक छवि का चयन करता हूं, छवि को नई गतिविधि में भेजा जाना चाहिए जहां चयनित छवि सेट की जाएगी पृष्ठभूमि के रूप में। हालांकि, मैं गैलरी से छवियां प्राप्त करने में सक्षम हूं लेकिन जैसे ही मैं एक चुनता हूं, एप्लिकेशन क्रैश हो जाता है। अग्रिम धन्यवादएक गतिविधि से दूसरे गतिविधि में एक बिटमैप छवि पास करें
गतिविधि -1 (चित्र गैलरी में दिखाए जाते हैं और चयनित छवि को नई पर भेजा जाता है गतिविधि)
public class Gallery extends Activity {
private static int RESULT_LOAD_IMAGE = 1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);
Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri contentUri = data.getData();
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String tmppath = cursor.getString(column_index);
Bitmap croppedImage = BitmapFactory.decodeFile(tmppath);
// Bitmap croppedImage = BitmapFactory.decodeFile(croppedImage);
Intent intent = new Intent(Gallery.this,GesturesActivity.class);
intent.putExtra("bmp",croppedImage);
startActivity(intent);
Log.v("sending image","sending image");
}
}
}
गतिविधि -1 (XML)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
>
<ImageView
android:id="@+id/imgView"
android:layout_width="fill_parent"
android:layout_weight="1" android:layout_height="wrap_content"></ImageView>
<Button
android:layout_height="wrap_content"
android:text="Load Picture"
android:layout_width="wrap_content"
android:id="@+id/buttonLoadPicture"
android:layout_weight="0"
android:layout_gravity="center"></Button>
</LinearLayout>
गतिविधि -2 (गतिविधि जहां चयनित छवि स्क्रीन की पृष्ठभूमि छवि के रूप में स्थापित किया जाना चाहिए)
public class GesturesActivity extends Activity {
private final int MENU_CAMERA = Menu.FIRST;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
Bitmap bmp = (Bitmap)this.getIntent().getParcelableExtra("bmp");
BitmapDrawable background = new BitmapDrawable(bmp);
getWindow().setBackgroundDrawable(background); //background image of the screen
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.advert);
View view = new SandboxView(this, bitmap);
setContentView(view);
}
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
menu.add(0, 11, 0, "Take Snapshot");
return super.onPrepareOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}
}
चेक [इस] (http://stackoverflow.com/a/6647023/1265724) –
आप पोस्ट logcat – Prachi