This BroadcastReceiver + Service + KeyEvent, they work on any activity, 
however the application that I need to run in the background and when 
pressing a control button of a SmartTV the BroadcastReceiver must be 
listening, the service must be activated and a screen (Activity / Fragment) 
open in Foreground.


Em quinta-feira, 17 de novembro de 2016 14:25:51 UTC-3, MrEdusi escreveu:
>
> My BroadcastReceiver will not start I will post the code below if someone 
> can point me the error thank you<uses-permission 
> android:name="android.permission.INTERNET" 
> />
>
>
> <receiver
>
>     android:enabled="true"
>     android:name="BroadcastReceiver"
>     android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
>
>
>     <intent-filter>
>
>         <action android:name="android.intent.action.BOOT_COMPLETED" />
>
>
>     </intent-filter>
>
> </receiver>
>
> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
>
> <service android:name="ComandosDoControle">
> </service>
>
>
>
>
> public class BroadcastReceiver extends android.content.BroadcastReceiver {
>
>     @Override
>     public void onReceive(Context context, Intent intent) {
>         Intent i = new Intent(context, ComandosDoControle.class);
>         Log.d("Iniciado....","BroadcastReceiver");
>         context.startService(i);
>
>     }
>
>
>
> }
>
>
> ublic class ComandosDoControle extends Service
>         implements View.OnKeyListener{
>
>     public int onStartComand(Intent intent, int flags, int startid){
>         return Service.START_STICKY;
>     }
>
>
>     //ACESSO A OUTROS APPS
>     @Override
>     public IBinder onBind(Intent intent) {
>         return null;
>     }
>
>     @Override
>     public boolean onKey(View v, final int keyCode, final KeyEvent event) {
>
>         new Thread(new Runnable() {
>
>             public void run() {
>
>                 if (keyCode == event.KEYCODE_ENTER) {
>
>                     Log.d("Clicado....","ComandosDoControle");
>
>                   //  Toast.makeText(getApplicationContext(), "Botão do 
> controle pegou!", Toast.LENGTH_LONG).show();
>
>                 }else{
>
>                    // Toast.makeText(getApplicationContext(), "Botão do 
> controle não pegou!", Toast.LENGTH_LONG).show();
>                 }
>             }
>         }).start();
>
>         return true;
>
>     }
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/d82f5ee5-c420-4585-a0d2-434f7590c5ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to