Logging during calling state in Android -
everyboday. trying log information such phonenumber, calling time , on during calling state in android. tried build codes following below:
package com.test.dialuplog; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.telephony.phonestatelistener; import android.telephony.telephonymanager; import android.util.log; import android.widget.toast; public class incomingbroadcastreceiver extends broadcastreceiver { string mphonenumber; public static incomingbroadcastreceiver pthis; @override public void onreceive(context context, intent intent) { telephonymanager telephonymanager = (telephonymanager) context.getsystemservice(context.telephony_service); telephonymanager.listen(new customphonestatelistener(context), phonestatelistener.listen_call_state); } public class customphonestatelistener extends phonestatelistener { //private static final string tag = "phonestatechanged"; context context; //context make toast if required public customphonestatelistener(context context) { super(); this.context = context; } @override public void oncallstatechanged(int state, string incomingnumber) { super.oncallstatechanged(state, incomingnumber); switch (state) { case telephonymanager.call_state_idle: //when idle i.e no call toast.maketext(context, "phone state idle", toast.length_long).show(); break; case telephonymanager.call_state_offhook: //when off hook i.e in call //make intent , start service here toast.maketext(context, "phone state off hook", toast.length_long).show(); break; case telephonymanager.call_state_ringing: //when ringing toast.maketext(context, "phone state ringing", toast.length_long).show(); break; default: break; } } } }
and wrote codes in androidmanifest.xml this:
<uses-permission android:name="android.permission.call_phone" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/theme.black.notitlebar.fullscreen"> <receiver android:name=".incomingbroadcastreceiver"> <intent-filter> <action android:name="android.intent.action.phone_state"/> </intent-filter> </receiver> <activity android:name=".splashactivity" android:configchanges="orientation" android:screenorientation="portrait" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application>
after coded, called phone different one. nothing happened, codes followed open source, nothing happened. there has experienced? if is, please teach me wrong. thank you.
Comments
Post a Comment