radimkliment revised this gist 2 hours ago. Go to revision
No changes
radimkliment revised this gist 3 hours ago. Go to revision
1 file changed, 6 insertions, 2 deletions
AndroidManifest.xml
| @@ -1,5 +1,9 @@ | |||
| 1 | - | <receiver android:name=".YourBrodcastReceiverClass" android:exported="true"> | |
| 1 | + | <receiver | |
| 2 | + | android:name=".YourBrodcastReceiverClass" | |
| 3 | + | android:exported="true" | |
| 4 | + | android:permission="android.permission.ACCESS_COARSE_LOCATION" | |
| 5 | + | > | |
| 2 | 6 | <intent-filter> | |
| 3 | - | <action android:name="android.intent.action.BOOT_COMPLETED"/> | |
| 7 | + | <action android:name="android.intent.action.SEND_SMS"/> | |
| 4 | 8 | </intent-filter> | |
| 5 | 9 | </receiver> | |
radimkliment revised this gist 3 hours ago. Go to revision
No changes
radimkliment revised this gist 3 hours ago. Go to revision
2 files changed, 1 insertion, 2 deletions
OwnBroadcast.kt
| @@ -3,7 +3,6 @@ intent.setAction("com.example.broadcast.MY_NOTIFICATION") | |||
| 3 | 3 | intent.putExtra("data", "Notice me!") | |
| 4 | 4 | ||
| 5 | 5 | // android:priority attribute or IntentFilter.setPriority() | |
| 6 | - | ||
| 7 | 6 | sendBroadcast(intent) | |
| 8 | 7 | ||
| 9 | 8 | // restrict broadcasts to the set of apps that hold certain permissions | |
RegisterOwn.kt
| @@ -7,7 +7,7 @@ class OwnBroadcast : BroadcastReceiver() { | |||
| 7 | 7 | ||
| 8 | 8 | // Android 16 priority | |
| 9 | 9 | val filter = IntentFilter().apply { | |
| 10 | - | priority = 0 | |
| 10 | + | priority = 0 // 0 - 100 | |
| 11 | 11 | } | |
| 12 | 12 | ||
| 13 | 13 | // Register the receiver with the filter | |
radimkliment revised this gist 3 hours ago. Go to revision
2 files changed, 6 insertions, 5 deletions
MyBroadcastReceiver.kt (file deleted)
| @@ -1,5 +0,0 @@ | |||
| 1 | - | public class MyBroadcastReceiver : BroadcastReceiver() { | |
| 2 | - | override fun onReceive(context : Context, intent: Intent) { | |
| 3 | - | ||
| 4 | - | } | |
| 5 | - | } | |
Registration.kt
| @@ -1,3 +1,9 @@ | |||
| 1 | + | public class MyBroadcastReceiver : BroadcastReceiver() { | |
| 2 | + | override fun onReceive(context : Context, intent: Intent) { | |
| 3 | + | ||
| 4 | + | } | |
| 5 | + | } | |
| 6 | + | ||
| 1 | 7 | BroadcastReceiver myBroadcastReceiver = new MyBroadcastReceiver(); | |
| 2 | 8 | IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); | |
| 3 | 9 | filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); | |
radimkliment revised this gist 3 hours ago. Go to revision
2 files changed, 19 insertions, 21 deletions
OwnBroadcast.kt
| @@ -9,27 +9,6 @@ sendBroadcast(intent) | |||
| 9 | 9 | // restrict broadcasts to the set of apps that hold certain permissions | |
| 10 | 10 | sendBroadcast(intent, Manifest.permission.SEND_SMS) | |
| 11 | 11 | ||
| 12 | - | ||
| 13 | - | class OwnBroadcast : BroadcastReceiver() { | |
| 14 | - | override fun onReceive(context: Context, intent: Intent) { | |
| 15 | - | val data = intent.getStringExtra("data") | |
| 16 | - | Log.d("BroadcastReceiver", "Received: $data") | |
| 17 | - | } | |
| 18 | - | } | |
| 19 | - | ||
| 20 | - | // Android 16 priority | |
| 21 | - | val filter = IntentFilter().apply { | |
| 22 | - | priority = 0 | |
| 23 | - | } | |
| 24 | - | ||
| 25 | - | // Register the receiver with the filter | |
| 26 | - | registerReceiver(object : BroadcastReceiver(){ | |
| 27 | - | override fun onReceive(context: Context?, intent: Intent?) { | |
| 28 | - | val data = intent?.getStringExtra("data") | |
| 29 | - | Log.d("BroadcastReceiver", "Received: $data") | |
| 30 | - | } | |
| 31 | - | }, filter) | |
| 32 | - | ||
| 33 | 12 | /* | |
| 34 | 13 | <receiver android:name=".YourBrodcastReceiverClass" android:exported="true"> | |
| 35 | 14 | <intent-filter> | |
RegisterOwn.kt(file created)
| @@ -0,0 +1,19 @@ | |||
| 1 | + | class OwnBroadcast : BroadcastReceiver() { | |
| 2 | + | override fun onReceive(context: Context, intent: Intent) { | |
| 3 | + | val data = intent.getStringExtra("data") | |
| 4 | + | Log.d("BroadcastReceiver", "Received: $data") | |
| 5 | + | } | |
| 6 | + | } | |
| 7 | + | ||
| 8 | + | // Android 16 priority | |
| 9 | + | val filter = IntentFilter().apply { | |
| 10 | + | priority = 0 | |
| 11 | + | } | |
| 12 | + | ||
| 13 | + | // Register the receiver with the filter | |
| 14 | + | registerReceiver(object : BroadcastReceiver(){ | |
| 15 | + | override fun onReceive(context: Context?, intent: Intent?) { | |
| 16 | + | val data = intent?.getStringExtra("data") | |
| 17 | + | Log.d("BroadcastReceiver", "Received: $data") | |
| 18 | + | } | |
| 19 | + | }, filter) | |
radimkliment revised this gist 3 hours ago. Go to revision
1 file changed, 20 insertions
OwnBroadcast.kt
| @@ -1,8 +1,15 @@ | |||
| 1 | 1 | var intent = Intent() | |
| 2 | 2 | intent.setAction("com.example.broadcast.MY_NOTIFICATION") | |
| 3 | 3 | intent.putExtra("data", "Notice me!") | |
| 4 | + | ||
| 5 | + | // android:priority attribute or IntentFilter.setPriority() | |
| 6 | + | ||
| 4 | 7 | sendBroadcast(intent) | |
| 5 | 8 | ||
| 9 | + | // restrict broadcasts to the set of apps that hold certain permissions | |
| 10 | + | sendBroadcast(intent, Manifest.permission.SEND_SMS) | |
| 11 | + | ||
| 12 | + | ||
| 6 | 13 | class OwnBroadcast : BroadcastReceiver() { | |
| 7 | 14 | override fun onReceive(context: Context, intent: Intent) { | |
| 8 | 15 | val data = intent.getStringExtra("data") | |
| @@ -10,6 +17,19 @@ class OwnBroadcast : BroadcastReceiver() { | |||
| 10 | 17 | } | |
| 11 | 18 | } | |
| 12 | 19 | ||
| 20 | + | // Android 16 priority | |
| 21 | + | val filter = IntentFilter().apply { | |
| 22 | + | priority = 0 | |
| 23 | + | } | |
| 24 | + | ||
| 25 | + | // Register the receiver with the filter | |
| 26 | + | registerReceiver(object : BroadcastReceiver(){ | |
| 27 | + | override fun onReceive(context: Context?, intent: Intent?) { | |
| 28 | + | val data = intent?.getStringExtra("data") | |
| 29 | + | Log.d("BroadcastReceiver", "Received: $data") | |
| 30 | + | } | |
| 31 | + | }, filter) | |
| 32 | + | ||
| 13 | 33 | /* | |
| 14 | 34 | <receiver android:name=".YourBrodcastReceiverClass" android:exported="true"> | |
| 15 | 35 | <intent-filter> | |
radimkliment revised this gist 4 hours ago. Go to revision
4 files changed, 3 insertions, 5 deletions
AndroidManifest.xml
| @@ -2,4 +2,4 @@ | |||
| 2 | 2 | <intent-filter> | |
| 3 | 3 | <action android:name="android.intent.action.BOOT_COMPLETED"/> | |
| 4 | 4 | </intent-filter> | |
| 5 | - | </receiver> | |
| 5 | + | </receiver> | |
MyBroadcastReceiver.kt
| @@ -2,4 +2,4 @@ public class MyBroadcastReceiver : BroadcastReceiver() { | |||
| 2 | 2 | override fun onReceive(context : Context, intent: Intent) { | |
| 3 | 3 | ||
| 4 | 4 | } | |
| 5 | - | } | |
| 5 | + | } | |
OwnBroadcast.kt
| @@ -11,11 +11,9 @@ class OwnBroadcast : BroadcastReceiver() { | |||
| 11 | 11 | } | |
| 12 | 12 | ||
| 13 | 13 | /* | |
| 14 | - | ||
| 15 | 14 | <receiver android:name=".YourBrodcastReceiverClass" android:exported="true"> | |
| 16 | 15 | <intent-filter> | |
| 17 | 16 | <action android:name="com.example.broadcast.MY_NOTIFICATION"/> | |
| 18 | 17 | </intent-filter> | |
| 19 | 18 | </receiver> | |
| 20 | - | ||
| 21 | 19 | */ | |
Registration.kt
| @@ -6,4 +6,4 @@ filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); | |||
| 6 | 6 | this.registerReceiver(myBroadcastReceiver, filter); | |
| 7 | 7 | ||
| 8 | 8 | // Un-registration | |
| 9 | - | unregisterReceiver(myBroadcastReceiver); | |
| 9 | + | unregisterReceiver(myBroadcastReceiver); | |
radimkliment revised this gist 4 hours ago. Go to revision
1 file changed, 21 insertions
OwnBroadcast.kt(file created)
| @@ -0,0 +1,21 @@ | |||
| 1 | + | var intent = Intent() | |
| 2 | + | intent.setAction("com.example.broadcast.MY_NOTIFICATION") | |
| 3 | + | intent.putExtra("data", "Notice me!") | |
| 4 | + | sendBroadcast(intent) | |
| 5 | + | ||
| 6 | + | class OwnBroadcast : BroadcastReceiver() { | |
| 7 | + | override fun onReceive(context: Context, intent: Intent) { | |
| 8 | + | val data = intent.getStringExtra("data") | |
| 9 | + | Log.d("BroadcastReceiver", "Received: $data") | |
| 10 | + | } | |
| 11 | + | } | |
| 12 | + | ||
| 13 | + | /* | |
| 14 | + | ||
| 15 | + | <receiver android:name=".YourBrodcastReceiverClass" android:exported="true"> | |
| 16 | + | <intent-filter> | |
| 17 | + | <action android:name="com.example.broadcast.MY_NOTIFICATION"/> | |
| 18 | + | </intent-filter> | |
| 19 | + | </receiver> | |
| 20 | + | ||
| 21 | + | */ | |
radimkliment revised this gist 4 hours ago. Go to revision
1 file changed, 0 insertions, 0 deletions
gistfile1.txt renamed to Registration.kt
File renamed without changes