tags:

views:

59

answers:

1

Hi experts, I would like to share a url from my android application. I would like to share this url through the installed applications in my device(bluetooth, facebook, google mail, messaging etc.).

Given below is the code

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SendURL extends Activity {
    /** Called when the activity is first created. */
    Button button;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        button = (Button) findViewById(R.id.Button01);
        button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Intent picMessageIntent = new Intent(
                android.content.Intent.ACTION_SEND);
                picMessageIntent.setType("plain/text");

                /**
                 * //Code for sending image
                 * picMessageIntent.setType("image/jpeg"); File downloadedPic =
                 * new
                 * File("/sdcard/download/"+"1287567819_Einstein_1_JPEG.jpg");
                 * picMessageIntent.putExtra(Intent.EXTRA_STREAM,
                 * Uri.fromFile(downloadedPic));
                 */

                startActivity(Intent.createChooser(picMessageIntent,
                        "Send your url using:"));
            }
        });
    }
}

When I press a button called share, the installed applications in the phone which can share this url, should be listed like this. The user can select an application from this list and share the url through the chosen application(gmail, facebook, messaging etc.). With the given code, I get only gmail and bluetooth. I do not get facebook, messaging etc. Please advise, in order that I can send the url through all the applications in the phone which are capable of doing this.

Any help in this regard is appreciated. Looking forward, Regards

+1  A: 

Try adding a subject and some text - at the moment you're not sharing a url, just creating a blank message.

Try something like this:

Intent picMessageIntent = new Intent(
android.content.Intent.ACTION_SEND);
picMessageIntent.putExtra(Intent.EXTRA_SUBJECT, "my url subject");
picMessageIntent.putExtra(Intent.EXTRA_TEXT, "Go to url: "+"http://google.com/");
picMessageIntent.setType("plain/text");

startActivity(Intent.createChooser(picMessageIntent, "Send your url using:"));

Replace "my url subject" and "Go to url " +"http://google.com/" with the subject and url you wish to share.

Colin Pickard
Ok..thx alot..i will check the way you told..i reconfirm once again..i need to send it through the installed and default applications in the phone(facebook, messaging etc.)
@Colin Pickard - Try adding a subject and some text - at the moment you're not sharing a url, just creating a blank message. I tried this, but still facebook and messaging is not shown in chooser as seen here -http://www.4shared.com/photo/8jlZgwNB/share.html . Please advise.
Any android experts who know about this, please help.
I do not know why I do not get ample support from this forum. This is not my first experience here. I am quite sure the queries which I ask here are technically doable stuffs. What I seek is just some expert supports.After plenty of google search only, I seek for expert support here. StackOverflow, kindly live up to our expectations...