Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- html
- FLUTTER
- Java
- jQuery
- Eclipse
- tomcat
- release unsigned
- android fragment
- Exception
- java error
- release Apk
- Android
- R프로그래밍
- apache gzip
- DataTable
- CSS사용법
- android error
- 안드로이드
- Kotlin
- JavaScript
- error
- Program type already present
- fragment
- Android Apk 이름
- spring
- css
- Android Apk
- Android Apk 이름 변경
- Firebase
- MySQL
Archives
- Today
- Total
selfstarter
BroadcastReciver app to app in Android 본문
BroadcastReciver app to app
- BroadcastReciver란 Android 시스템 등으로 부터 어떤 이벤트가 발생했을 시 수신등록을 했다면 수신 알람을 받는 기능이다.
- 그러므로 A와 B 둘 다 같은 폰에 있는 app이어야 한다
BroadcastReciver app to app Example
send broadcast app
send broadcast to B when I click send button
public void click(View v) { Intent intent = new Intent(); intent.setAction("com.test.broadcastexample"); // action name intent.putExtra("data", "Notice me senpai!"); getApplicationContext().sendBroadcast(intent); }
Receive broadcast app
AndroidManifest.xml
<receiver android:name=".MyBroadcastReceiver" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="com.test.broadcastexample"/> </intent-filter> </receiver>
MainActivity.java
BroadcastReceiver br = new MyBroadcastReceiver(); IntentFilter filter = new IntentFilter("com.ahope.broadcastexample"); this.registerReceiver(br, filter);
MyBroadcastReceiver.java
public class MyBroadcastReceiver extends BroadcastReceiver { private static final String TAG = "MyBroadcastReceiver"; @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, intent.getAction(), Toast.LENGTH_LONG).show(); } }
'App > Android' 카테고리의 다른 글
Animation simple example in Android (0) | 2020.03.30 |
---|---|
Simple Current Time Example (0) | 2020.03.26 |
Using Android getIdentifier (0) | 2020.03.12 |
androidx 사용하지 않기 (0) | 2020.03.12 |
Solve transformDexArchiveWithExternalLibsDexMergerForDevDebug Error (0) | 2020.03.09 |
Comments