android - Launch activity by dialing a number -
i've created appropriate boradcastreceiver
, registered in manifest.xml
, here problem: if application has been launched , hanging in background, dialing number bring front. if has not been launched dialing number have no effect.
how can fix this? test on xiaomi mi4 miui6 if that's important.
here's code (i use scala):
manifest.xml:
<uses-permission android:name="android.permission.process_outgoing_calls"/> ... <receiver android:name="dialergate" android:enabled="true" android:exported="true"> <intent-filter android:priority="1"> <action android:name="android.intent.action.new_outgoing_call"/> </intent-filter> </receiver>
broadcastreceiver:
class dialergate extends broadcastreceiver { def onreceive(context: context, intent: intent) = if (intent.getaction equals intent.action_new_outgoing_call) { val phoneno = intent.getextras getstring intent.extra_phone_number val prefs = context.getsharedpreferences("prefs", context.mode_private) val number = prefs.getstring(abstractkit.launch_number, null) log.d("wallet-phone", s"dialed number: $phoneno, saved number: $number") log.d("wallet-phone-ok", (number == phoneno).tostring) val = new intent i.setclassname("com.app.wallet", "com.app.wallet.mainactivity") i.setflags(intent.flag_activity_new_task | intent.flag_activity_clear_top | intent.flag_activity_single_top) val appcontext = context.getapplicationcontext appcontext.startactivity(i) //if (number == phoneno) context startactivity new intent(context, target) //context stopservice intent } }
from simple user perspective, cannot done (its security feature).
starting honeycomb android doesn't allow broadcast receivers invoked until application run @ least once.
its simpler allow program run @ least once (during boot common one), , have intent close app if not time use it.
check further details on how implement additional receivers may need do.
Comments
Post a Comment