Android NFC Phone Call And SMS Sender

Hi Guys, today it’s time to take a look at how to call and send SMS to a mobile number once a NFC tag is detected.
This is basically an Android App to automate mobile device.
Let’s jump into coding.

package com.thul.nfc;

import com.thul.nfc.R;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter.MalformedMimeTypeException;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends Activity {
String phone = "1234567890"; // Replace with your mobile number
String yellow_tag = "04D658B2003E80"; // Replace with your NFC Tag ID
String white_tag = "044C54B2003E80"; // Replace with your NFC Tag ID
String red_tag = "04E25FB2003E80"; // Replace with your NFC Tag ID
String blue_tag = "04385BB2003E80"; // Replace with your NFC Tag ID
String green_tag = "04FC4EB2003E80"; // Replace with your NFC Tag ID

NfcAdapter mAdapter;
IntentFilter[] mFilters;
PendingIntent mPendingIntent;

void resolveIntent(Intent intent) {
Context context = getApplicationContext();
int duration = Toast.LENGTH_LONG;

String action = intent.getAction();

if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {

Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] extraID = tagFromIntent.getId();

StringBuilder sb = new StringBuilder();
for (byte b : extraID) {
sb.append(String.format("%02X", b));

String tagID = sb.toString();
Log.e("nfc ID", tagID);

String name;

if (tagID.equals(yellow_tag)){

Intent callIntent = new Intent(Intent.ACTION_CALL);
name = "yellow";
else if (tagID.equals(white_tag)){

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phone, null, "Hi this is a Test message", null, null);
name = "White";

else if (tagID.equals(red_tag)){

name = "Red";

else if (tagID.equals(blue_tag)){

name = "Blue";

else if (tagID.equals(green_tag)){

name = "Green";

else {

name ="Unknown Tag";

Toast toast = Toast.makeText(context, name, duration);;


String[][] mTechLists = new String[][] { new String[] { NfcA.class.getName() } };
Intent intent = getIntent();

protected void onCreate(Bundle savedInstanceState) {

mPendingIntent = PendingIntent.getActivity(this, 0,
new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

IntentFilter ndef1 = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
mFilters = new IntentFilter[] {

try {

} catch (MalformedMimeTypeException e) {
throw new RuntimeException("fail", e);
mAdapter = NfcAdapter.getDefaultAdapter(this);

if (getIntent() != null){


public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(, menu);
return true;

public void onResume() {
mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);

public void onNewIntent(Intent intent) {
Log.i("Foreground dispatch", "Discovered tag with intent: " + intent);

public void onPause() {


The mobile number and NFC tag IDs must be changed accordingly for your use.

You can find NFC tags in the image link below. Cheers.


Leave a Reply

Your email address will not be published. Required fields are marked *