java - Android Auto text reply to phone call not working -
i have created app initiates broadcast receiver class should auto respond phone calls text message. receiver working following exception:
java.lang.illegalargumentexception: invalid destinationaddress
please help!!!
main activity:
package com.biapps.makin_biscuits; import android.content.broadcastreceiver; import android.content.context; import android.content.contextwrapper; import android.media.audiomanager; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.content.intent; import android.telephony.phonestatelistener; import android.telephony.telephonymanager; import android.view.view; import android.widget.imagebutton; import android.util.log; import android.widget.textview; import android.widget.toast; import com.biapps.contact; import com.biapps.databasehandler; import java.util.list; public class mainactivity extends appcompatactivity { //set object labels , states here private imagebutton icon; private audiomanager am; private imagebutton people; private imagebutton ring; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); = (audiomanager) getsystemservice(context.audio_service); icon = (imagebutton) findviewbyid(r.id.icon); icon.setonclicklistener(imgbuttonhandler); people = (imagebutton) findviewbyid(r.id.people); people.setonclicklistener(peoplebuttonhandler); ring = (imagebutton) findviewbyid(r.id.ring); } int buttonstate = 0; public view.onclicklistener imgbuttonhandler = new view.onclicklistener() { public void onclick(view v) { if (buttonstate == 0) { icon.setimageresource(r.drawable.buttonup); buttonstate = 1; am.setringermode(0); toast.maketext(getapplicationcontext(), "go!!", toast.length_short).show(); intent intent = new intent(); intent.addflags(intent.flag_include_stopped_packages); intent.setaction("android.intent.action.trigger"); sendbroadcast(intent); } else { icon.setimageresource(r.drawable.button); buttonstate = 0; am.setringermode(2); toast.maketext(getapplicationcontext(), "come back!!", toast.length_short).show(); } } };
incoming call reveiver:
package com.biapps.makin_biscuits; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.os.bundle; import android.telephony.phonestatelistener; import android.telephony.smsmanager; import android.telephony.telephonymanager; import android.util.log; import android.widget.toast; /** * created jake on 3/21/2016. */ public class incomingcallreceiver extends broadcastreceiver { private static final string tag = "mylistener"; private context mcontext; private intent mintent; @override public void onreceive(context context, intent intent) { mcontext = context; mintent = intent; telephonymanager tm = (telephonymanager)mcontext.getsystemservice(context.telephony_service); int events = phonestatelistener.listen_call_state; tm.listen(phonestatelistener, events); } private final phonestatelistener phonestatelistener = new phonestatelistener() { @override public void oncallstatechanged(int state, string incomingnumber) { super.oncallstatechanged(state, incomingnumber); log.i(tag, "number: " + incomingnumber + ""); string phonenr = incomingnumber; switch (state) { case telephonymanager.call_state_idle: toast.maketext(mcontext,"no-one calling " + phonenr,toast.length_long).show(); break; case telephonymanager.call_state_ringing: // -- check international call or not. if (incomingnumber.startswith("1865")) { toast.maketext(mcontext,"knoxville calling " + phonenr + "",toast.length_long).show(); smsmanager smsmanager = smsmanager.getdefault(); smsmanager.sendtextmessage(phonenr, null, "i'm busy bruh", null, null); } else { toast.maketext(mcontext,"other calling: " + phonenr + "", toast.length_long).show(); smsmanager smsmanager = smsmanager.getdefault(); smsmanager.sendtextmessage(phonenr, null, "i'm busy bruh", null, null); } } } }; }
manifest:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.biapps.makin_biscuits"> <uses-sdk android:minsdkversion="4" /> <uses-permission android:name="android.permission.read_contacts" /> <uses-permission android:name="android.permission.process_outgoing_calls" /> <uses-permission android:name="android.permission.read_phone_state" /> <uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.read_external_storage" /> <uses-permission android:name="android.permission.send_sms"/> <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> <activity android:name=".contactslist"> <intent-filter> <category android:name="android.intent.category.alternative" /> </intent-filter> </activity> <receiver android:name=".incomingcallreceiver" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.intent.action.phone_state" /> <action android:name="android.intent.action.trigger" /> </intent-filter> </receiver> </application> </manifest>
answering own question. problem assigning string phonenr incomingnumber. removing step solves problem.
Comments
Post a Comment