IncomingCallBroadcast.java
packagecom.swamys.incomingcallbroadcast;
importandroid.content.BroadcastReceiver;
importandroid.content.Context;
importandroid.content.Intent;
import android.os.Bundle;
importandroid.telephony.TelephonyManager;
import android.widget.Toast;
public classIncomingCallBroadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
String status = bundle.getString(TelephonyManager.EXTRA_STATE);
if(status.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
String Phone_number = bundle
.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast.makeText(context, "Incoming call: " + Phone_number,
Toast.LENGTH_LONG).show();
}
}
}
Manifest.xml
<?xml version="1.0"encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swamys.incomingcallbroadcast"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.swamys.incomingcallbroadcast.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<receiver android:name="com.swamys.incomingcallbroadcast.IncomingCallBroadcast">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver> </application>
</manifest>
Komentar
Posting Komentar