34 - Share button - Bir yazıyı bir fotoğrafı facebook, gmail,whatsapp,mesajlar vs ile paylaşmak
http://stackoverflow.com/questions/27119857/using-shareactionprovider-with-button-in-layout
Complete Example :
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bv = (Button)findViewById(R.id.button1);
bv.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT,"My new app");
String applink = "www.hurriyet.com.tr";
share.putExtra(Intent.EXTRA_TEXT,"Try my new app : " + applink);
startActivity(Intent.createChooser(share,"Share via"));
}
});
Button bv2 = (Button)findViewById(R.id.button2);
bv2.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT,"My new app");
String applink = "www.milliyet.com.tr";
share.putExtra(Intent.EXTRA_TEXT,"Try my new app : " + applink);
startActivity(share);
}
});
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bv = (Button)findViewById(R.id.button1);
bv.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT,"My new app");
String applink = "www.hurriyet.com.tr";
share.putExtra(Intent.EXTRA_TEXT,"Try my new app : " + applink);
startActivity(Intent.createChooser(share,"Share via"));
}
});
Button bv2 = (Button)findViewById(R.id.button2);
bv2.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT,"My new app");
String applink = "www.milliyet.com.tr";
share.putExtra(Intent.EXTRA_TEXT,"Try my new app : " + applink);
startActivity(share);
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:orientation="vertical"
tools:context="oiyioz.com.a16_sharebutton.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="Button1"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="Button2"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:orientation="vertical"
tools:context="oiyioz.com.a16_sharebutton.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button1"
android:text="Button1"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="Button2"/>
</LinearLayout>
Output :
Hiç yorum yok:
Yorum Gönder