java - How to start sevice in dialer (default or stock dialer) of android -
i want start service when dialer (default or stock dialer) open. service toasts message. how start service dialer. startservice
command working in mainactivity
, not working while dialer open.
my code shown below :
manifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.chatheads"> <uses-permission android:name="android.permission.system_alert_window" /> <uses-permission android:name="android.permission.dial_action" /> <uses-permission android:name="android.permission.call_phone" /> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme"> <activity android:name=".mainactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <service android:name=".myservice" android:enabled="true" android:exported="true" /> <activity android:name=".secondactivity"></activity> </application> </manifest>
mainactivity.java
package com.example.chatheads; import android.support.v7.app.appcompatactivity; import android.content.intent; import android.os.bundle; import android.text.method.dialerkeylistener; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; public class mainactivity extends appcompatactivity { button startservice,stopservice; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); startservice=(button)findviewbyid(r.id.startservice); stopservice=(button)findviewbyid(r.id.stopservice); if(getintent().getaction().equals(intent.action_dial)) { intent intent = new intent(getbasecontext(), myservice.class); startservice(intent); } startservice.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { startservice(new intent(getapplication(), myservice.class)); } }); stopservice.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { stopservice(new intent(getapplication(), myservice.class)); } }); } }
myservice.java
package com..service; import android.app.service; import android.content.intent; import android.os.ibinder; import android.widget.toast; public class myservice extends service { @override public void oncreate() { // todo auto-generated method stub super.oncreate(); toast.maketext(this, "service created", toast.length_long).show(); } @override public int onstartcommand(intent intent, int flags, int startid) { // todo auto-generated method stub toast.maketext(this, "service started", toast.length_long).show(); intent.getstringextra("my_message"); //stopself(); return super.onstartcommand(intent, flags, startid); } @override public void ondestroy() { // todo auto-generated method stub super.ondestroy(); toast.maketext(this, "service stopped", toast.length_long).show(); } @override public ibinder onbind(intent arg0) { // todo auto-generated method stub return null; } }
this code not working. service starting when startservice calling in mainactivity. when dialer open not working.
Comments
Post a Comment