android - how to get call number info for outgoing and incoming calls -


i have made broadcast receiver , whenever outgoing call event happens fetches outgoing number. want integrate incoming number too. sharing code.

callreceiver class

public class callreceiver extends broadcastreceiver {     telephonymanager tmanager;      @override     public void onreceive(context context, intent intent) {         final string outgoingcallnumber = intent.getstringextra(intent.extra_phone_number);         log.i("clapp", outgoingcallnumber);     } } 

manifest file

<receiver android:name=".callreceiver">     <intent-filter>         <action android:name="android.intent.action.new_outgoing_call"/>         <action android:name="android.intent.action.phone_state" />     </intent-filter> </receiver> 

error-log :

06-01 10:57:36.209: e/dalvikvm(29762): not find class 'android.content.restrictionsmanager', referenced method com.salesforce.androidsdk.config.runtimeconfig.getrestrictions 06-01 10:57:36.219: e/dalvikvm(29762): not find class 'android.content.restrictionsmanager', referenced method com.salesforce.androidsdk.config.runtimeconfig.hasrestrictionsprovider 06-01 10:57:36.329: e/imgsrv(29762): :0: pvrdrmopen: tp3, ret = 49 06-01 10:57:36.209: e/dalvikvm(29762): not find class 'android.content.restrictionsmanager', referenced method com.salesforce.androidsdk.config.runtimeconfig.getrestrictions 06-01 10:57:36.219: e/dalvikvm(29762): not find class 'android.content.restrictionsmanager', referenced method com.salesforce.androidsdk.config.runtimeconfig.hasrestrictionsprovider  06-01 10:57:36.329: e/imgsrv(29762): :0: pvrdrmopen: tp3, ret = 49  06-01 10:57:36.329: e/imgsrv(29762): :0: pvrdrmopen: tp3, ret = 50  06-01 10:57:36.329: e/imgsrv(29762): :0: pvrdrmopen: tp3, ret = 50  06-01 10:57:36.329: e/imgsrv(29762): :0: pvrdrmopen: tp3, ret = 50  06-01 10:57:52.709: e/androidruntime(29762): fatal exception: main  06-01 10:57:52.709: e/androidruntime(29762): process: io.concret.callloggerapp, pid: 29762  06-01 10:57:52.709: e/androidruntime(29762): java.lang.runtimeexception: unable start receiver io.concret.callloggerapp.callreceiver: java.lang.nullpointerexception: println needs message  06-01 10:57:52.709: e/androidruntime(29762):   @ android.app.activitythread.handlereceiver(activitythread.java:2593)  06-01 10:57:52.709: e/androidruntime(29762):   @ android.app.activitythread.access$1700(activitythread.java:139)  06-01 10:57:52.709: e/androidruntime(29762):   @ android.app.activitythread$h.handlemessage(activitythread.java:1369) 06-01 10:57:52.709: e/androidruntime(29762):    @ android.os.handler.dispatchmessage(handler.java:102) 06-01 10:57:52.709: e/androidruntime(29762):    @ android.os.looper.loop(looper.java:149) 06-01 10:57:52.709: e/androidruntime(29762):    @ android.app.activitythread.main(activitythread.java:5257) 06-01 10:57:52.709: e/androidruntime(29762):    @ java.lang.reflect.method.invokenative(native method) 06-01 10:57:52.709: e/androidruntime(29762):    @ java.lang.reflect.method.invoke(method.java:515) 06-01 10:57:52.709: e/androidruntime(29762):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 06-01 10:57:52.709: e/androidruntime(29762):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:609) 06-01 10:57:52.709: e/androidruntime(29762):    @ dalvik.system.nativestart.main(native method) 06-01 10:57:52.709: e/androidruntime(29762): caused by: java.lang.nullpointerexception: println needs message 06-01 10:57:52.709: e/androidruntime(29762):    @ android.util.log.println_native(native method) 06-01 10:57:52.709: e/androidruntime(29762):    @ android.util.log.println_filter(log.java:105) 06-01 10:57:52.709: e/androidruntime(29762):    @ android.util.log.i(log.java:187) 06-01 10:57:52.709: e/androidruntime(29762):    @ io.concret.callloggerapp.callreceiver.onreceive(callreceiver.java:23) 06-01 10:57:52.709: e/androidruntime(29762):    @ android.app.activitythread.handlereceiver(activitythread.java:2586) 06-01 10:57:52.709: e/androidruntime(29762):    ... 10 more 

check if intent received incoming call or outgoing call in receiver class

public class callreceiver extends broadcastreceiver { telephonymanager tmanager;  @override public void onreceive(context context, intent intent) {     if (intent.getaction().equals("android.intent.action.new_outgoing_call")) {       // outgoing call       final string outgoingcallnumber = intent.getstringextra(intent.extra_phone_number);       log.i("clapp", outgoingcallnumber);     }     else {          // incoming call          string incomingcallnumber = intent.getextras().getstring(telephonymanager.extra_incoming_number);          log.i("clapp", incomingcallnumber);     }  } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -