Monday, 20 January 2014

Some popular implicit intents in Android

When coding Android, we must do very much with intent (Explicit and implicit) to start activities and applications. Below are some popular implicit intent to start some work like open webbrowser, send mail, sms, open/add contact .... Hoping useful for you.


btnBrowser = (Button) findViewById(R.id.btnBrowser);
  btnBrowser.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View arg0) {
    intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse("http://google.com.vn"));
    startActivity(intent);
   }
  });
  btnSearch = (Button) findViewById(R.id.btnSearch);
  btnSearch.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    intent = new Intent(Intent.ACTION_WEB_SEARCH);
    intent.putExtra(SearchManager.QUERY, "abc");
    startActivity(intent);
   }
  });
  btnDial = (Button) findViewById(R.id.btnDial);
  btnDial.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    intent = new Intent(Intent.ACTION_CALL);
    intent.setData(Uri.parse("tel:1234567890"));
    startActivity(intent);
   }
  });
  btnShowPicture = (Button) findViewById(R.id.btnShowPicture);
  btnShowPicture.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    intent = new Intent(
      Intent.ACTION_PICK,
      android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    startActivity(intent);
   }
  });
  btnGoContact = (Button) findViewById(R.id.btnGoContact);
  btnGoContact.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    intent = new Intent(Intent.ACTION_PICK,
      ContactsContract.Contacts.CONTENT_URI);
    startActivity(intent);
   }
  });
  btnInsertContact = (Button) findViewById(R.id.btnInsertContact);
  btnInsertContact.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    intent = new Intent(Intent.ACTION_INSERT,
      ContactsContract.Contacts.CONTENT_URI);
    intent.putExtra(ContactsContract.Intents.Insert.NAME, "Tien");
    intent.putExtra(ContactsContract.Intents.Insert.EMAIL,
      "tienlbhoc@gmail.com");
    intent.putExtra(ContactsContract.Intents.Insert.PHONE,
      "01234567890");
    startActivity(intent);
   }
  });
  
  btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
  btnSendSMS.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    intent = new Intent(Intent.ACTION_VIEW);         
                intent.setData(Uri.parse("sms:"));
                intent.setType("vnd.android-dir/mms-sms");
                intent.putExtra("sms_body", "Here you can set the SMS text to be sent"); 
                intent.putExtra("address",  "1234567890");
                startActivity(intent);
   }
  });
  
  btnSendEmail = (Button) findViewById(R.id.btnSendEmail);
  btnSendEmail.setOnClickListener(new OnClickListener() {

   @Override
   public void onClick(View v) {
    intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/html");
    intent.putExtra(Intent.EXTRA_EMAIL, "tienlbhoc@gmail.com");
    intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");

    startActivity(Intent.createChooser(intent, "Send Email"));
   }
  });


Wednesday, 1 January 2014

Netbeans or Eclipse IDE for code

I am a fan of Netbeans. And in this article, I will tell about why I prefer Netbeans to Eclipse.


Netbeans is owned by Oracle
With java developer, Netbeans is owned by Oracle (Oracle is owner of java too), so we can be confident in its future development and support. In present, many support document can be found in Netbeans and Oracle website. Example:


Java EE & Java Web Learning Trail
https://netbeans.org/kb/trails/java-ee.html

Creating a RESTful Web Service Using NetBeans IDE
http://docs.oracle.com/cd/E19226-01/820-7627/giqaa/index.html


Many default good plugins/functions

Undeniably Eclipse has a lot of plugins and extensions. But many of them are not as good as Netbeans plugins/functions or must pay to use.
When I coding java, javascript, php, c/c++, html5. Netbeans is better and easier than Eclipse, Aptana (Eclipse plugin for code web) and more stable.

But with python (use pydev) or Android (adt) and many languages out of default in Netbeans, Eclipse plugins are better. But java (all feature), web, php, c++ are almost full for me, Android now is changing to android studio and with pydev, I use pycharm, Eclipse is only a secondary IDE of them.


Easy for install and more compatibility


Netbeans has full functions like tomcat, glassfish servers for web and newest features, drag and drop GUI function in install file, embed webkit to debug, javascript, templates,libs (like jquery) for php, java, javascript ... install process in Linux or Windows has wizard (very modern).
In Eclipse, only download, extract and use (with minimum demand) but need download and install server, GUI drag drop plugin for java swing plugins (must pay), and ....

Netbeans and eclipse need install jdk first but Netbeans has "Netbeans with jdk" version in Oracle website.


In ubuntu with unity, Netbeans support create launcher and stick to unity, eclipse error with menu.

Error menu of Eclipse in unity tientuts
Can fix it but I don't like must search google and fix every install.

Autocomplete and support code

Eclipse support autocomplete too but not as good as Netbeans. See follow.

Autocomplete expression language don't show in Eclipse but Netbeans has:




Netbeans support many shortcut key and template code better than Eclipse.
When I coding, I often use:
 psvm<tab> to print lines:

public static void main(String[] args) {
}

sout<tab> to  System.out.println("");

fori<tab> to for an array
forl<tab> to for an list
form<tab> to for a map
or for + ctrl space to select or view shortcut at the right.
Shotcut code templates


view more in Help -> Keyboard shortcuts card.

With Eclipse, we can only do with for and ctrl+space and enter or select .



And Netbeans has some other advanced like:

Show line of start block code

In dotnet, visual studio is the best comfortable IDE , and in java, you can see image of it in Netbeans (and more).


Stable
I use Netbeans for code java, web and Eclipse for code Android. And I think Netbeans more stable than Eclipse.


Lightweight
In the past, Eclipse is more lightweight than Netbeans, but now, Eclipse is the same and after install some plugin, it is really heavy and not stable.