my.xml (carpeta menu)
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context="com.elpoeta.essential.spanishfortravellers.MainActivity" > <item android:id="@+id/set_donate" android:title="Donar" ></item> </menu>
import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; public class MyActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.my, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.set_donate: AlertDialog.Builder alertDialogDonate = new AlertDialog.Builder(MyActivity.this); // Setting Dialog Message alertDialogDonate.setTitle("Donar"); alertDialogDonate.setMessage("Tu donación ayuda a que esta aplicación mejore. \nDesde ya muchas gracias!"); alertDialogDonate.setCancelable(true); alertDialogDonate.setPositiveButton("DONATE", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Uri.Builder uriBuilder = new Uri.Builder(); uriBuilder.scheme("https").authority("www.paypal.com").path("cgi-bin/webscr"); uriBuilder.appendQueryParameter("cmd", "_donations"); uriBuilder.appendQueryParameter("business", "ramiro.madriaga@gmail.com"); uriBuilder.appendQueryParameter("lc", "US"); uriBuilder.appendQueryParameter("item_name", "heygringolearnspanish"); uriBuilder.appendQueryParameter("no_note", "1"); uriBuilder.appendQueryParameter("no_shipping", "1"); uriBuilder.appendQueryParameter("currency_code", "USD"); Uri payPalUri = uriBuilder.build(); Intent viewIntent = new Intent(Intent.ACTION_VIEW, payPalUri); startActivity(viewIntent); } }); alertDialogDonate.show(); return true; //case R.id.action_settings: //Toast.makeText(getApplicationContext(), "holaaa", Toast.LENGTH_SHORT).show(); } return true; } }
Excelente, me ayudo mucho!!
ResponderEliminarAun funciona?
ResponderEliminar