- no main.xml works in background so no application icon generated.
- give following permission in Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.PhoneCallSMS" android:versionCode="1" android:versionName="1.0">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<receiver android:name=".PhoneCallSMS">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.PhoneCallSMS" android:versionCode="1" android:versionName="1.0">
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<receiver android:name=".PhoneCallSMS">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
</application>
</manifest>
PhoneCallSMS.java
package com.PhoneCallSMS;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.widget.Toast;
public class PhoneCallSMS extends BroadcastReceiver {
//@SuppressWarnings("deprecation")
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if(telephony.getCallState() == TelephonyManager.CALL_STATE_RINGING)
{
Bundle bundle = intent.getExtras();
String phone_number = bundle.getString("incoming_number");
String message = "Sorry, I am busy...will call you back..!";
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phone_number, null, message, null, null);
Log.e("Msg SENT", "SMS SENT TO RECEPIENT");
Log.w("Incoming call", phone_number);
Toast.makeText(context,
"Hello,You have incoming call from..." + phone_number,
Toast.LENGTH_LONG).show();
}
}
}
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.telephony.gsm.SmsManager;
import android.util.Log;
import android.widget.Toast;
public class PhoneCallSMS extends BroadcastReceiver {
//@SuppressWarnings("deprecation")
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
if(telephony.getCallState() == TelephonyManager.CALL_STATE_RINGING)
{
Bundle bundle = intent.getExtras();
String phone_number = bundle.getString("incoming_number");
String message = "Sorry, I am busy...will call you back..!";
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phone_number, null, message, null, null);
Log.e("Msg SENT", "SMS SENT TO RECEPIENT");
Log.w("Incoming call", phone_number);
Toast.makeText(context,
"Hello,You have incoming call from..." + phone_number,
Toast.LENGTH_LONG).show();
}
}
}
No comments:
Post a Comment