2010-10-20 106 views
0

我想从我的android应用程序共享一个url。我想通过我的设备上安装的应用程序(蓝牙,脸书,谷歌邮件,消息等)分享这个网址。通过安装的应用程序发送消息

下面给出的是代码

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:")); 
      } 
     }); 
    } 
} 

当我按下一个叫做分享按钮,在手机,它可以共享这个网址安装的应用程序,应列出像this。用户可以从这个列表中选择一个应用程序,并通过选择的应用程序(Gmail,Facebook,消息等)共享该URL。 使用给定的代码,我只能获得gmail和蓝牙。我没有得到脸书,消息等。请告知,为了我可以通过手机中的所有应用程序发送URL,这是有能力做到这一点。

赞赏这方面的任何帮助。 展望未来, Regards

回答

1

尝试添加主题和一些文本 - 目前您没有共享网址,只是创建一条空白消息。

尝试这样:

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:")); 

更换"my url subject""Go to url " +"http://google.com/"你想分享的主题和网址。

+0

好的..thx很多..我会检查你告诉的方式..我再次确认..我需要通过安装和默认的应用程序在手机(脸谱,消息等)发送 – user264953 2010-10-20 12:41:56

+0

尝试添加一个主题和一些文本 - 目前你没有分享一个网址,只是创建一个空白的消息。我尝试了这一点,但仍然没有在选择器中显示facebook和消息,如此处所示--http://www.4shared.com/photo/8jlZgwNB/share.html。请指教。 – user264953 2010-10-21 05:19:56

+0

任何知道此事的android专家,请帮忙。 – user264953 2010-10-21 10:58:15

相关问题