package com.example.demo1;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.content.Intent;
import android.net.Uri;
public class MainActivity extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn =(Button) findViewById(R.id.button1);
btn.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
/*
new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("인사")
.setMessage("안녕하세요!!")
.setNeutralButton("닫기", null)
.show();
*/
showAlertDialog1();
}
private void showAlertDialog1() {
final String[] cars = new String[] { "트위터", "페이스북", "카카오톡", "문자전송" };
new AlertDialog.Builder(this)
.setTitle("공유")
.setItems(cars, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(cars[which]=="문자전송")
{
/*
Toast.makeText(MainActivity.this,
"cars : " + cars[which],
Toast.LENGTH_SHORT)
.show();
*/
shareSms();
}
else if(cars[which]=="트위터"){
shareTwitter();
}
else if(cars[which]=="페이스북"){
shareFacebook();
}
}
}).setNeutralButton("닫기", null).show();
}
private void shareSms() {
String message = "안녕하세요
http://www.iwav.co.kr ";
String subject = "문제 제목 입니다. ";
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT,subject);
share.putExtra(Intent.EXTRA_TEXT, message);
startActivity(Intent.createChooser(share, "문자 보내기"));
}
private void shareTwitter()
{
String twitterUri = "
http://twitter.com/intent/tweet?text=";
String marketUri = Uri.encode("안녕 하세요 감자 감자
http://iwav.co.kr/sub_read.html?uid=100");
Intent shareOnTwitterIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(twitterUri + marketUri));
startActivity(shareOnTwitterIntent);
}
private void shareFacebook()
{
String twitterUri = "
http://m.facebook.com/sharer.php?u=";
String marketUri = Uri.encode("
http://iwav.co.kr/sub_read.html?uid=100");
String marketMessage = Uri.encode("&t=안녕 하세요 감자 감자 ");
Intent shareOnTwitterIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(twitterUri + marketUri+ marketMessage));
startActivity(shareOnTwitterIntent);
}
}