开发者

Sending message through installed applications

开发者 https://www.devze.com 2023-01-21 02:53 出处:网络
I would like to share a url from my android application. I would like to share this url through the installed applic开发者_运维技巧ations in my device(bluetooth, facebook, google mail, messaging etc.)

I would like to share a url from my android application. I would like to share this url through the installed applic开发者_运维技巧ations 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消