Display screenshot image from one activity to another activity - android

I am developing playing video application and taking screenshot of running video and display a screenshot in next activity, i am playing video and taking screenshot and i am not able to display screenshot in next activity please check my code and give me changes.
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
image = (ImageView) findViewById(R.id.ImageView01);
// image.setBackgroundDrawable(bitmapDrawable);
String bitmap = image.toString();
System.out.println("Image getting++++++ : " + bitmap);
Intent intent = new Intent(VideoDemo.this, ScreenshotView.class);
intent.putExtra("BitmapImage", bitmap);
startActivity(intent);
public class ScreenshotView extends Activity
{ private String filename;
private ImageButton back;
private ImageView screenshot;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.screenshot);
screenshot =(ImageView)findViewById(R.id.screen);
back = (ImageButton)findViewById(R.id.backbutton);
back.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
finish();
}
});
System.gc();
Intent i = getIntent();
Bitmap bitmap = (Bitmap) i.getParcelableExtra("BitmapImage");
screenshot.setImageBitmap(bitmap);
}
}

Here your "bitmap" object is a string.
And you are passing a string object to your next activity.
That is why, you are not able to set image in you ImageView screenshot.

Can you try the below code and lemme know whether you fixed it.
Sending Object
Here is the code to send the Object from one to other class. One Important thing to send the Object is the class should implement the Serializable class.
The below Red Colored text should be same.
//MainActivity.java
Intent i = new Intent(MainActivity.this,startActivity.class);
ObjectClassName object = new ObjectClassName();
i.putExtra("THIS", Object);
Receiving Object
// startActivity.java
Intent i = getIntent();
ObjectClassName obj = (ObjectClassName) getIntent().getSerializableExtra("THIS");//
TypeCasting needed

Related

Assign image resource in an image view with string

(1) I am using recyleview to fetch image, text & audio file from API. For text I used volley & for image use picasso, what I will use for audio file.
(2) after fetch the image & text when apply onclicklistener pass the info to another activity. Can pass only text not images.
What I need to do to solve this problem?
this is adapter part
viewHolder.textViewStory.setText(banglaItem.getStoryName());
viewHolder.textViewWritter.setText(banglaItem.getWritterName());
Picasso.get().load(banglaItem.getStoryImage()).fit().into(viewHolder.imageView);
viewHolder.linear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,AudioActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("storyName",banglaItem.getStoryName());
intent.putExtra("storyImage",banglaItem.getStoryImage());
context.startActivity(intent);
}
});
this is the new activity part
public class AudioActivity extends AppCompatActivity {
TextView name;
ImageView image;
String nameStory;
String imageStory;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio);
name = findViewById(R.id.audioName);
image = findViewById(R.id.audioImage);
nameStory = getIntent().getStringExtra("storyName");
imageStory = getIntent().getStringExtra("storyImage");
name.setText(nameStory);
int resourceId = getResources().getIdentifier(imageStory,"drawable", getPackageName());
image.setImageResource(resourceId);
}
}
(1.) if you have complete url of your audio file then you can directly stream audio file using media player classes provided by android.
(2.) you are passing storyImage in next activity ,which is a url that you get from api. so you have to find same on next activity i.e
TextView name;
ImageView image;
String nameStory;
String imageStory;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_audio);
name = findViewById(R.id.audioName);
image = findViewById(R.id.audioImage);
nameStory = getIntent().getStringExtra("storyName");
imageStory = getIntent().getStringExtra("storyImage");
name.setText(nameStory);
Picasso.get().load(imageStory).fit().into(image);
//here image story contain url that you sent through first activity. As picasso uses cache, it will load (already loaded image in first activity) very smoothly from it cache.
}

How to pass an camera image to another activity?

I saw a video of how to put an camera access on android studio but I didn´t have much space in my current activity so I made an clicklistener on the image and when the user clicks on image, it goes to another activity where the image appears bigger, but when I click on the image it goes to the other acivity but doesn´t show the image. I saw other questions but or they ask about how to pass an image that is on drawable resources or the answer doesn´t fit me.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fazer_perguntas);
photoCamera = (RelativeLayout) findViewById(R.id.photoCamera);
photo = (ImageView) findViewById(R.id.photo);
photo2 = (ImageView) findViewById(R.id.photo2);
photo3 = (ImageView) findViewById(R.id.photo3);
photoCamera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent camera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camera,0);
}
});
photo.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent p = new Intent(getApplicationContext(),BigPhoto.class);
p.putExtra("idphoto",photo.getId());
p.putExtra("idphoto2",photo2.getId());
p.putExtra("idphoto3",photo3.getId());
startActivity(p);
}
});
{
#Override
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
photo.setImageBitmap(bitmap);
Intent selfiSrc = new Intent(this, BigPhoto.class);
selfiSrc.putExtra("data",bitmap);
startActivity(selfiSrc);
}
}
}
This is part of my firstactivity java class. photo2 and photo3 are other imageviews that I will do the same thing for photo.
package com.example.ritalopes.help;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
public class BigPhoto extends AppCompatActivity {
ImageView photo, photo2, photo3, bigphoto;
private Uri path;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_big_photo);
photo = (ImageView) findViewById(R.id.photo);
photo2 = (ImageView) findViewById(R.id.photo2);
photo3 = (ImageView) findViewById(R.id.photo3);
bigphoto = (ImageView) findViewById(R.id.bigphoto);
Intent pho = getIntent();
int image1 = pho.getIntExtra("idphoto",0);
int image2 = pho.getIntExtra("idphoto2",0);
int image3 = pho.getIntExtra("idphoto3",0);
Intent take = getIntent();
Bitmap bitmap = (Bitmap) take.getParcelableExtra("data");
bigphoto.setImageBitmap(bitmap);
}}
This is my secondactivity javaclass where I want to pass the image(s) to. I tried that code envolving a Uri but didn´t worked out.
Thanks in advance for your responses.
Your code is not very clear...
First, you have to add an OnClickListener for all images, not only for photo
Then, you have to pass extra data to Intent, like you've done. But, don't pass the ID of the imageView but the drawable ID you want to show in fullscreen.
Do you want to display images for drawable ? Or Bitmaps ? If bitmap, I think intent.putExtra("data", bitmap) will work as Bitmap is Parcelable.
if your purpose is sending an image in order to preview image in the another activity. I recommend you try to use this library. just add it in your gradle file in your project.
https://github.com/chathuralakmal/AndroidImagePopup
this preview image library have using Picasso Library to you can show your preview is so easy. and it also contain close button for you.
it help me , i hope this would save you time.

Intent putExtra bitmap issue

I have the following code:
((ImageButton)findViewById(R.id.fish)).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(StartupActivity.this, GameActivity.class);
intent.putExtra(NAME_EXTRA, ((EditText)findViewById(R.id.name)).getText().toString().trim());
intent.putExtra(TYPE_EXTRA, FishTypes.FISH.toString());
intent.putExtra(WORLD_TYPE_EXTRA, worldType);
intent.putExtra(LOGO_EXTRA, BitmapFactory.decodeResource(getResources(), R.drawable.logo));
startActivity(intent);
}
});
If I start activity and click on ImageButton it send me to the same Activity I was before (StartupActivity). However if I comment out the last putExtra like this:
//intent.putExtra(LOGO_EXTRA, BitmapFactory.decodeResource(getResources(), R.drawable.logo));
Then it works fine. It sends me to the GameActivity as I want. What could be the problem?
EDIT
My GameActivity looks like this:
public class GameActivity extends Activity {
public static GamePanel gamePanel;
public static String name;
public static FishTypes type;
public static String worldType;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(getWindow().FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
name = getIntent().getStringExtra(StartupActivity.NAME_EXTRA);
type = FishTypes.parse(getIntent().getStringExtra(StartupActivity.TYPE_EXTRA));
worldType = getIntent().getStringExtra(StartupActivity.WORLD_TYPE_EXTRA);
gamePanel = new GamePanel(this);
//gamePanel.bitmaps.put("logo", (Bitmap)getIntent().getParcelableExtra(StartupActivity.LOGO_EXTRA));
setContentView(gamePanel);
if(!StartupActivity.isNetworkAvailable()) {
Toast.makeText(StartupActivity.getInstance(), "You have no internet connection...", Toast.LENGTH_LONG).show();
finish();
}
}
#Override
protected void onDestroy() {
if(gamePanel.client != null)
gamePanel.client.disconnect();
StartupActivity.getInstance().reopen();
super.onDestroy();
}
}
What I want to achieve is preloading this bitmap in StartupActivity and then just send it to the GameActivity to the GamePanel and then draw it on the canvas as a loading image. I can't load this image in GameActivity because it will be late to show it. Do you understand?
So first of all, there is an Intent payload limit, as far as I know there is a limit of 1MB, but in some cases can be 500kb. If this limit is overreached the app will crash, in your case crashed and restarted.
Second of all, Bundle and Intent are used to send small amount of data to Activity and Fragments, usually some configs/params so that the activity/fragment will know how to build itself.
Third, is a really bad practice to pass around instances of bitmaps, you need just a second of distraction to create a huge leak in your app, that will cost you a lot of time to find and fix it.
Now the solution for you is really simple. You can pass the id of the bitmap you want to use in the next activity.
Intent intent = new Intent(StartupActivity.this, GameActivity.class);
intent.putExtra(NAME_EXTRA, ((EditText)findViewById(R.id.name)).getText().toString().trim());
intent.putExtra(TYPE_EXTRA, FishTypes.FISH.toString());
intent.putExtra(WORLD_TYPE_EXTRA, worldType);
intent.putExtra(LOGO_EXTRA, R.drawable.logo); // R.drawable.logo is actually an int.
startActivity(intent);
In your GameActivity
#Override
public void onCreate(Bundle savedInstanceState) {
setContentView(...)
int myAwesomeDrawable = getIntent().getExtra(LOGO_EXTRA, 0); // 0 is default value in case nothing is added to the key
if(myAwesomeDrawable != 0){ // safety check
imageView.setImageResource(myAwesomeDrawable);
// or do whatever you like with it.
}

Android how to pass image from image view and text from text from one activity to another activity

Hi in android i know how to send image from one activity to another and send text from text view to another,separately. But i want to know in an activity we have both text view and image view.But my need is i want to send both text and image from one activity to another.Any suggestions is welcomed.
Thank you.
What do you mean by sending along an image? For passing a string, use Intent extras and Bundle.
In your first activity...
someButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
intent.putExtra("text_contents", someTextView.getText().toString();
startActivity(intent);
}
});
In the second activity onCreate(), you retrieve the intent extras you passed via Bundle...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String someString = bundle.getString("text_contents");
}
}
If your "image" is an R.drawable resource, then you could simply add that as well to the intent extras:
intent.putExtra("image_resource", R.drawable.some_image_resource);
And retrieve it from the Bundle like:
int someImageResource = bundle.getInt("image_resource");
And from there you can apply it to some ImageView:
someImageView.setImageResource(someImageResource);
EDIT: made a slight correction + if your "image" is a bitmap, then see Anjali's answer.

Pass Bitmap from one Activity to another

I tried to convert a TextView into Bitmap and I tried to pass it to another Activity on a single Button click.
My code is:
Activity sending the Bitmap :
save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
View view0 = txt1.getRootView(); //txt1 is a TextView
view0.setDrawingCacheEnabled(true);
view0.buildDrawingCache();
Bitmap bmp0 = Bitmap.createBitmap(view0.getDrawingCache());
Intent in = new Intent(Meme_make.this,S_meme.class);
in.putExtra("bm0" , bmp0);
startActivity(in);
}
Activity Receiving the Bitmap :
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sm);
main1 = (ImageView) findViewById(R.id.imageView1);
Bitmap bitmap = getIntent().getParcelableExtra("bm0");
main1.setImageBitmap(bitmap);
}
But when I click on the button , the activity is automatically closing and taking me back to the Main launcher Activity.
How to do this without any issues ?
You have
in.putExtra("bm0" , bmp0);
and
Bitmap bitmap = getIntent().getParcelableExtra("bmp0");
In particular bm0 vs bmp0, you may just be missing a p.
But in general I would also cast your retrieved bitmap to a bitmap
Bitmap bitmap = (Bitmap)getIntent().getParcelableExtra("bmp0");
Try this code snippet.
Send bitmap
Intent intent = new Intent(this, ActivityName.class);
intent.putExtra("Bitmap", bitmap);
Retrieve Bitmap
Bitmap bitmap = (Bitmap) getIntent().getParcelableExtra("Bitmap");

Categories

Resources