Reputation: 27
i am a new android developer . i am writing a application that get the incoming caling number and do some stuff. i have one Activity " Main_Activity " the code in Main_Activity is this :
package com.example.callchecker;
import android.os.Bundle;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;
public class Main_Activity extends BroadcastReceiver{public Main_Activity() {
// TODO Auto-generated constructor stub
}
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
try {
Bundle extras=intent.getExtras();
if (extras !=null){
String state = extras.getString(TelephonyManager.EXTRA_STATE);
Log.w("MY_DEBUG_TAG",state);
if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
String phonenumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
Log.w("MY_DEBUG_TAG", phonenumber);
}
}
} catch (Exception e) {
// TODO: handle exception
Log.w("MY_DEBUG_TAG", e);
}
}
}
and the AndroidManifist.xml is this :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.callchecker"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.callchecker.Main_Activity"
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="Main_Activity" >
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
</application>
</manifest>
I just want to get the number and write it to LogCat But it is not working , i can not see any line in LogCat when i click on app icon it say " Unfortunately call checker has been stopped "
Upvotes: 0
Views: 128
Reputation: 54672
Make sure the following permission is used in manifest
<uses-permission android:name="android.permission.READ_PHONE_STATE" >
</uses-permission>
Upvotes: 1