explicit broadcast implemented

This commit is contained in:
2020-10-21 19:33:32 +02:00
parent 3c769ef513
commit 76f18dab01
7 changed files with 39 additions and 5 deletions

View File

@@ -2,7 +2,10 @@ package com.ploedige.broadcastsender;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@@ -11,4 +14,16 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void broadcast(View view){
Intent broadcastIntent = new Intent("com.ploedige.TESTBROADCAST");
broadcastIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
//since Android O implicit Broadcasts are disabled.
//this gets the component and makes an explicit broadcast
ComponentName componentName = new ComponentName(
"com.ploedige.broadcastreceiver",
"com.ploedige.broadcastreceiver.TestReceiver");
broadcastIntent.setComponent(componentName);
sendBroadcast(broadcastIntent);
}
}

View File

@@ -7,12 +7,25 @@
tools:context=".MainActivity">
<TextView
android:id="@+id/message_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:text="This is the Broadcast Sender App"
android:textSize="4mm"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:text="Send Broadcast"
android:onClick="broadcast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/message_tv"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>