Reputation: 545
Hello i create one broadcast test but no work
Manifest:
<receiver android:name=".BeaconsBroadcast"
android:exported="false">
<intent-filter>
<action android:name="com.example.android.kontacktestbeacons.BeaconsBroadcast"/>
</intent-filter>
</receiver>
in my 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");}
}
mi broadcast class:
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();
}
}
in 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
where my error?
Upvotes: 0
Views: 984
Reputation: 545
Hello im fine by manifest
<receiver android:name="BeaconsBroadCast">
<intent-filter>
<action android:name="com.tutorialspoint.CUSTOM_INTENT">
</action>
</intent-filter>
</receiver>
in application tag
Upvotes: 0
Reputation: 361
You are declaring BeaconsBroadcast as a BroadcastReceiver but are using startService(i) to invoke it which is causing the issue.
You need to use the sendBroadcast(i) function to send a broadcast to a BroadcastReceiver.
Also Since you have set android:exported="false" for BroadcastReceiver use
LocalBroadcastManager.getInstance(Context context).sendBroadcast(Intent)
Upvotes: 3