am sending an image with help of intent as follow
Uri profileImage = Uri.parse("android.resource://Tset/res/drawable-hdpi/arr.jpeg");
details.setType("image/png");
details.putExtra(Intent.EXTRA_STREAM, profileImage);
startActivity(details);
how do i can get the image path in my receiving end activity ?
Try This
Pass image url from current activity using intent
Intent myIntent = new Intent(this, MyImageViewActivity.class);
Bundle bundle = new Bundle();
bundle.putString("image", path);
myIntent.putExtras(bundle);
startActivityForResult(myIntent, 0);
Here path is
String path="android.resource://Tset/res/drawable-hdpi/arr.jpeg"
in your receiving activity
Bundle bundle = this.getIntent().getExtras();
String path = bundle.getString("image");
Finally i done it with help of id of the image as follow ! !
thanks for all of ur reply ! !
profilePictureID=R.drawable.image name;//name of image in drawable folder dont use extensions like.jpg and all
IntentObject.putExtra("ImageID",profilePictureID);
startActivity(IntenetObject);
In receiving activity
int pictureId=getIntent().getIntExtra("ImageID",0);
profilePicture.setImageResource(pictureId);
Try this..
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "image/png");
startActivity(intent);
Related
I am trying to send an image that in ListView from onItemClick to onCreate method in another activity .
This is my code :
Activity 1
product_imageView= findViewById(R.id.product_imageView);
byte[] image = savedInstanceState.getByteArray("Product image");
Bitmap receivedImage = BitmapFactory.decodeByteArray(image,0,image.length);
//here it give me error
product_imageView.setImageResource(receivedImage);
Activity 1
String productimage = productslist.get(position).getProductImage();
Bundle bundle = new Bundle();
bundle.putByteArray("Product image", productimage.getBytes());
intent.putExtras(bundle);
startActivity(intent);
Please try this
First convert imageview to bitmap.
product_imageView.buildDrawingCache();
Bitmap bitmap = product_imageView.getDrawingCache();
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtra("BitmapImage", bitmap);
In second Activity please include this line:
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
imageview.setImageBitmap(bitmap);
Why are you sending images between activities?, why not just place your image in drawable folder and pass the name or path of the image to the next activity and then display or do whatever you want to do with it.
You do it like this
put your image in drawable folder for example image1.png.
then all you do is parse a string with the name for the image to the second activity example:
Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
intent.putExtra("image", "image1.png");
startActivity(intent);
On the second activity you display for instance:
Intent intent = getIntent();
String imageStr = intent.getStringExtra("image");
ImageView imageView = (ImageView)findViewById(R.id.myimage);
imageView.setImageResource(R.drawable.image1);
I hope code is correct, forgive my mistakes I wrote this in a hurry.
I know this question has been asked a lot, but I have no idea where I went wrong..
So I sent some data through one activity and retrieving it from the other activity.
FirstActivity
Timber.i("Photo img : %s", posterUrl);
String url = AppConstants.IMAGE_BASE_URL+
AppConstants.POSTER_SIZE_ORIGINAL+ posterUrl;
Intent i = new Intent(this, ImageFullActivity.class);
i.putExtra(AppConstants.IMAGE_URL, url);
startActivity(i);
Recieving Activity
Intent i = new Intent();
String imageUrl = i.getStringExtra(AppConstants.IMAGE_URL);
Timber.i("GOt image url %s", imageUrl);
Picasso.with(this)
.load(imageUrl)
.into(image);
And I checked. I am not passing null through the extras. The posterUrl is a valid string.
You need to use getIntent() to get the intent instance that started the next activity as
getIntent().getStringExtra
instead of creating a new empty one
//Intent i = new Intent(); remove
Intent i = getIntent(); // or do this
Try this
//Intent i = new Intent();
String imageUrl = getIntent().getStringExtra(AppConstants.IMAGE_URL);
Timber.i("GOt image url %s", imageUrl);
Picasso.with(this)
.load(imageUrl)
.into(image);
OR
Bundle bundle = getIntent().getExtras();
String imageUrl = bundle.getString(AppConstants.IMAGE_URL);
Timber.i("GOt image url %s", imageUrl);
Picasso.with(this)
.load(imageUrl)
.into(image);
String imageUrl = getIntent().getStringExtra(AppConstants.IMAGE_URL);
You need to get the intent by getIntent() method
Problem is that you are trying to create new intent in your receiving activity which does not have your data what you passed in other activity.
To get the intent what you passed in other activity use getIntent().
Intent i = getIntent();
Here this intent will be holding your data you passed from other activity.
i used to add header to intent as below:
Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(baseUrl));
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle bundle = new Bundle();
TokenManager manager = TokenManager.getTokenManager();
bundle.putString("Authorization", manager.getAuthorization());
bundle.putString("Content-Type","application/x-www-form-urlencoded");
myIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
mContext.startActivity(myIntent);
but it seems it does not work on newest version of google chrome. it ignores headers as there is no header hence i encounter with authorization problem.
can anybody help me? ( i need to use intent not webview )
Try this solution
I have a Map object that I stored header information. Then the following:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
Bundle bundle = new Bundle();
if(mExtraHeader!=null){
for(String key: mExtraHeader.keySet()){
bundle.putString(key, mExtraHeader.get(key));
}
}
i.putExtra(Browser.EXTRA_HEADERS, bundle);
startActivity(i);
I am writing a browser, and want implement a button "add site to home screen" so the site icon (apple-touch-icon) and title would be fetched by launcher and displayed.
I have found the code which does that -
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(getPackageName(), "Browser");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.addCategory(Intent.ACTION_PICK_ACTIVITY);
shortcutIntent.putExtra("EXTRA_URL", webView.getUrl());
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, webView.getTitle());
intent.putExtra(Intent.EXTRA_ORIGINATING_URI, webView.getUrl());
//TODO change to apple-touch icon
Bitmap btm = webView.getFaviconImage();
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, btm);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
But, unfortunately, intent in onCreate is without any extra data :
if (getIntent() != null){
Intent intent = getIntent();
//empty
String url1 = intent.getStringExtra("EXTRA_URL");
}
How should I pass extra parametr (URL), to launcher so that further i could read it ?
Try this
intent.putExtra(EXTRA_URL, Uri.parse(webView.getUrl()));
So I managed to solve this task using next code :
Send shortcut to launcher:
Intent shortcutIntent = new Intent(getApplicationContext(), BrowserActivity.class);
shortcutIntent.putExtra(BrowserUnit.EXTRA_URL, webView.getUrl());
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, webView.getTitle());
//TODO change to apple-touch icon
Bitmap btm = webView.getFaviconImage();
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, btm);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(intent);
Retreive proper url:
//in onCreate
if (getIntent() != null){
//if we are launching from launcher shortcut
Bundle bundel = getIntent().getExtras();
if (bundel != null) {
String url = bundel.getString(BrowserUnit.EXTRA_URL);
onSearchPressed(url);
}
}
I am new to Android application development and I want to show an Intent as Dialog. How can I do this?
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
I want to show this on dialog. Please suggest me.
Try this,
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File("/sdcard/test.mp4");
intent.setDataAndType(Uri.fromFile(file), "video/*");
startActivity(intent);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File("/sdcard/test.mp3");
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
Give android:style/Theme.Dialog in the corresponding activity in the manifest file.