Привет я создать один тест вещания, но не работуAndroid BroadcastReceiver ошибка
Manifest:
<receiver android:name=".BeaconsBroadcast"
android:exported="false">
<intent-filter>
<action android:name="com.example.android.kontacktestbeacons.BeaconsBroadcast"/>
</intent-filter>
</receiver>
в моем MainActivity:
protected void onStop() {
super.onStop();
try{
Log.e("ENTRO ","ENTRO");
Intent i = new Intent();
i.setAction("com.example.android.kontacktestbeacons.BeaconsBroadcast");
startService(i);
}catch (Exception e){Log.e("ERROR","ERRR");}
}
миль вещания класс:
public class BeaconsBroadcast extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("ENTRO ","EBTROPOOOOO RECIVE");
Toast.makeText(context, "Se ha pulsado el botón.", Toast.LENGTH_SHORT)
.show();
}
}
в logcat:
12-02 11:12:59.551 28588-28588/com.mydomain.myapplication W/ContextImpl﹕ Implicit intents with startService are not safe: Intent { act=com.example.android.kontacktestbeacons.BeaconsBroadcast } android.content.ContextWrapper.startService:494 com.example.android.kontacktestbeacons.MainActivity.onStop:101 android.app.Instrumentation.callActivityOnStop:1235
12-02 11:12:59.552 927-2008/? W/ActivityManager﹕ Unable to start service Intent { act=com.example.android.kontacktestbeacons.BeaconsBroadcast } U=0: not found
где моя ошибка?
Привет, я использую this.sendBroadcast (i); no mark error, но не работает:/mi class BeaconsBroacast не выполняет:/ – Luis
use LocalBroadcastManager.getInstance (this) .sendBroadcast (i), потому что вы определили его как android: exported = "false", поэтому он будет принимать только локальную передачу. –
У меня есть @Override protected void onStop() { super.onStop(); try { Log.e ("ENTRO", "ENTRO"); Intent i = new Intent(); i.setAction («com.example.android.kontacktestbeacons.BeaconsBroadcast»); LocalBroadcastManager.getInstance (this) .sendBroadcast (i); } улов (Исключение е) {Log.e ("ERROR", "Errr");}} – Luis