java - Reading the incoming phone number -


i new android developer . writing application incoming caling number , stuff. have 1 activity " main_activity " code in main_activity :

    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 androidmanifist.xml :

    <?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 want number , write logcat not working , can not see line in logcat when click on app icon " unfortunately call checker has been stopped "

make sure following permission used in manifest

<uses-permission android:name="android.permission.read_phone_state" > </uses-permission> 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -