Created
January 31, 2014 20:24
-
-
Save arianimartins/8742365 to your computer and use it in GitHub Desktop.
Fazer ligação, navegar em site, adicionar contato na agenda e compartilhar contato
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//---------------------------------- Fazer ligação | |
Button btnnum; | |
btnnum = ((Button) this.findViewById(R.id.btnnumdetalhe)); | |
btnnum.setText(telefone.getDetalheuteis()); | |
btnnum.setOnClickListener(new OnClickListener() { | |
public void onClick(View v) { | |
Intent chamada = new Intent(Intent.ACTION_CALL); | |
chamada.setData(Uri.parse("tel:" + telefone.getDetalheuteis())); | |
startActivity(chamada); | |
} | |
}); | |
//---------------------------------- Navegar para Site | |
Button btnsite; | |
btnsite = ((Button) this.findViewById(R.id.btnsitedetalhe)); | |
btnsite.setText(telefone.getSiteuteis().replace("http://","")); | |
btnsite.setOnClickListener(new OnClickListener() { | |
public void onClick(View v) { | |
String url = telefone.getSiteuteis(); | |
Uri uriUrl = Uri.parse(url); | |
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl); | |
startActivity(launchBrowser); | |
} | |
}); | |
//---------------------------------- Adicionar Contato na Agenda | |
Button btnaddocontato; | |
btnaddocontato = ((Button) this.findViewById(R.id.btn_addcontato)); | |
btnaddocontato.setOnClickListener(new OnClickListener() { | |
public void onClick(View v) { | |
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); | |
ops.add(ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI) | |
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null) | |
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null) | |
.build()); | |
//------------------------------------------------------ Nome | |
if(telefone.getTitleuteis() != null){ | |
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) | |
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID,0) | |
.withValue(ContactsContract.Data.MIMETYPE, | |
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE) | |
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, | |
telefone.getTitleuteis()).build()); | |
} | |
//------------------------------------------------------ Número de Telefone | |
if(telefone.getDetalheuteis() != null){ | |
ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) | |
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) | |
.withValue(ContactsContract.Data.MIMETYPE, | |
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE) | |
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, | |
telefone.getDetalheuteis()) | |
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, | |
ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE).build()); | |
} | |
// Pede para o Contact Provider criar um novo contato | |
try{ | |
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); | |
AlertDialog.Builder builder = new AlertDialog.Builder(DetalheTelefone.this); | |
builder.setMessage("Contato adicionado!") | |
.setCancelable(false) | |
.setPositiveButton("OK", new DialogInterface.OnClickListener(){ | |
public void onClick(DialogInterface dialog, int id) { | |
finish(); | |
} | |
}); | |
builder.show(); | |
}catch (Exception e){ | |
e.printStackTrace(); | |
} | |
} | |
}); | |
//---------------------------------- Compartilhar Contato | |
Button btnsharecontato; | |
btnsharecontato = ((Button) this.findViewById(R.id.btn_sharecontato)); | |
btnsharecontato.setOnClickListener(new OnClickListener() { | |
public void onClick(View v) { | |
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); | |
sharingIntent.setType("text/plain"); | |
String shareBody = telefone.getTitleuteis() +"\n" + telefone.getDetalheuteis() +"\n" + telefone.getSiteuteis(); | |
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody); | |
startActivity(Intent.createChooser(sharingIntent, "Compartilhar com:")); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment