Sharing image from other apps unto my app - java

When a user shares an image to my app from another app, I want to receive it as an image and handle it.
I've already set up filters like this:
Now what I don't understand is how to actually receive the intent in my app nor how I could extract/handle an image from it.
I've tried googling the problem but no one seems to give a concrete answer on how to handle/receive the intent after setting up the filter.
I appreciate the help!

You can get the image uri in the activity like this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if (type.startsWith("image/")) {
Uri imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imageUri != null) {
// Do whatever you want here
}
}
}
}
You can check the link for other mime types Handle the Incoming Content

Related

How can I transfer data new intent

my Onbindview holder
Glide.with(holder.t1.getContext())
.load("http://example/example/images/" +data.get(position).getImage()).into(holder.img);
}
And my interface
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (iOtobusSaatleriInterface != null){
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION);
iOtobusSaatleriInterface.onItemClick(position);
Intent intent = new Intent(context,deneme.class);
intent.putExtra("name",data.get(position).getName());
intent.putExtra("resim", String.valueOf(Glide.with(itemView)
.load("http://example/example/images/")));
context.startActivity(intent);
}
}
});
my new activity
Intent intent = getIntent();
String name = intent.getStringExtra("name");
int goruntu = intent.getIntExtra("resim",0);
imageView.setImageResource(goruntu);
textView.setText(name);
finally my photo is not coming. I just can't get the image data in the new activity. This data is registered in mysql and I am pulling from the directory with retrofit.
New display
my imageview display
And my xml
You can pass the image as a string from screen A to screen B.
The batter way is to pass full URL in intent as String and receive it on another Activity.
Intent intent = new Intent(context,deneme.class);
intent.putExtra("name",data.get(position).getName());
intent.putExtra("resim","YOUR_FULL_URL");
At Another Activity
Intent intent = getIntent();
String name = intent.getStringExtra("name");
String goruntu = intent.getStringExtra("resim");
String.valueOf(Glide.with(imageView)
.load(goruntu)
textView.setText(name);
Without knowing more about why you are trying to send a raster image over IPC between activities, I think the best advice I can give you is to not try to do that.
Instead, simply send the URL in the intent and have Activity 2 use glide to load and display the image.

change markerSnippet at google maps on android

I have an activity called GatherActivity where I have an EditText. The user can input what ever he wants. Now I need the input of that EditText in a different class, called MapActivity.
I created an Intent to "put it over" in the other activity. But it doesn't work like I aspect it. the object/editText is allways a null object, so nothing is displayed as a markerSnippet.
Here my Code (GahterActivity) in a method onButtonClick():
public void onButtonClick(View view){
EditText editText_markerSnippet = (EditText) findViewById(R.id.editText_markerSnippet);
Intent intent = new Intent(this, MapActivity.class);
intent.putExtra("markerSnippet", editText_markerSnippet.getText().toString());
}
Code in MapActivity:
Bundle extras = getIntent().getExtras();
if(extras != null){
markerSnippet = extras.getParcelable("markerSnippet");
}else{
markerSnippet = "some extra info about your location"
}
in my marker snippet there is no text. so the else case is not in use here...
You're sending a String, but expecting a Parcelable in your activity.
In your MapActivity, change it to:
markerSnippet = extras.getString("markerSnippet");

Getting Null Values while passing data with intent from adapter to activity

This is probably a very basic question but I couldn't find the answer.
I need to pass data from RecyclerView but when I check it on related activity, data is null.
mvHolder.barcode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent s = new Intent(context, SummaryActivity.class);
s.putExtra("SUMMARY",sp.getDATA().get(i).getId_summary()); // data is not null
context.startActivity(s);
}
});
and this is how I try to achieve it :
Bundle extras = getIntent().getExtras();
if (extras != null) {
strBarcode = extras.getString("SUMMARY");
// and get whatever type user account id is
}
but when I debug it, it turns out that strBarcode is null. I don't know what the problem is, I guess my code should be works either. Please help me
Intent data = getIntent();
if (data != null) {
strBarcode = data.getStringExtra("SUMMARY");
// and get whatever type user account id is
}
Intent data = getIntent();
if (data != null) {
int strBarcode = data.getIntExtra("SUMMARY");
}
Please try this
Check if getIntent().hasExtra("SUMMARY") returns true.
If it does, make sure that sp.getDATA().get(i).getId_summary() returns a String.
The extra might be there, but you try to get as String, and it might
have different type.

Passing bundle instance to place picker intent

I am working on an android app whose main purpose is to update the working location of the employees by admin. Now when I want to change/update the location of an employee from my recycler view(list of employees connected with my UserManagerAdapter), I have to pass the user name of that employee to the place picker intent so that when the admin pick the desired location, the database of that user will be changed accordingly.
My Steps(2 Steps)
I have passed the username to the place picker intent as bundle.
My UserManagerAdapter
holder.locationTv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
launchPicker(data.get(position).getUserName());
}
});
private void launchPicker(String userName) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
Bundle bundle = new Bundle();
bundle.putString(USERNAME,userName);
try {
fragment.startActivityForResult(builder.build(fragment.getActivity()),PLACE_PICKER_REQUEST,bundle);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
I received the location request inside of a fragment and update the location of that particular user
My ManageUserFragment
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PLACE_PICKER_REQUEST){
if(resultCode == RESULT_OK){
Place place = PlacePicker.getPlace(getContext(),data);
address = place.getAddress().toString();
String latLng = place.getLatLng().toString();
latLang = latLng;
//update user's decided location
Bundle bundle = data.getExtras();
String userName = bundle.getString(USERNAME);// it returns null, Why?
updateLocation(latLang,userName);
Toast.makeText(getContext(), latLng, Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), getContext().getText(R.string.locationError), Toast.LENGTH_SHORT).show();
}
}
}
My constant is
public static final String USERNAME="Username";
Now,
My problem is
Why bundle.getString(USERNAME) always return null?
How to pass data to place picker intent so that we can receive it in
onActivityResult ?
After replicating your case and researching for a little bit, I found out that the third parameter in startActivityForResult() is not used to pass a bundle of values to the onActivityResult, it's used to pass options to Android itself, you can find those here. So if you want to pass any data you have to use an intent with putExtra("USERNAME", username), and you can retrieve it with getStringExtra("USERNAME"). It's explained in this answer as well.

Receiving data from other Android apps only works once

I'm trying to develop a simple app, which receives text from other android Apps and then open a browser.
I have implemented it as described in the documentation here:
https://developer.android.com/training/sharing/receive.html
It works, but only once.
The first time a text is shared from an other App, the browser is opened correctly.
But the second time only my app is opened, but not the browser.
What could be the reason for this?
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the intent that started this activity
Intent intent = getIntent();
// Get the action of the intent
String action = intent.getAction();
// Get the type of intent (Text or Image)
String type = intent.getType();
// When Intent's action is 'ACTION+SEND' and Type is not null
if (Intent.ACTION_SEND.equals(action) && type != null) {
// When tyoe is 'text/plain'
if ("text/plain".equals(type)) {
handleSendText(intent); // Handle text being sent
}
}
}
private void handleSendText(Intent intent) {
// Get the text from intent
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
openBrowser(sharedText);
}
}
private void openBrowser(String text) {
Toast.makeText(this, text, Toast.LENGTH_LONG).show();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com/api.php?text=" + text));
startActivity(browserIntent);
}
}
openBrowser method is called from the handleSendText method witch it is on the onCreate method , second time you open your app ( If you didnt press the back button ) your app is already created ! so the code will never execute.
Please check the life cycle of an android activity below
You may edit your code and call the openBrowser method on the onResume method or just make a button to call the method openBrowser Oncliking the button.

Categories

Resources