0
bc_from에서 bc_to로 브로드 캐스트하려고합니다. 내가 매니페스트에서 수신기를 정의하는 경우가 작동하지 않습니다app1에서 app2로 브로드 캐스트
registerReceiver(receiver, filter);
: 나는 활동 bc_to에서 사용하는 경우
그것은 잘 작동합니다.
나는 26 일 이래로 불가능하다고 문서에서 알 수 있습니다.
그래서 실행되지 않는 경우에도 Activity bc_to에 도달 할 솔루션을 찾고 있습니다.
감사
// package com.yotam17.ori.bc_from;
public class MainActivity extends AppCompatActivity {
private static final String BC_ACTION = "com.yotam17.ori.bc.Broadcast";
private void send() {
Intent intent = new Intent(BC_ACTION);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(intent);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
send();
}
}
그리고 bc_from 매니페스트는 containes 두 clases에 대한 코드 :
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<receiver android:name="com.yotam17.ori.bc_to.MyReceiver" >
<intent-filter>
<action android:name="com.yotam17.ori.bc.Broadcast"/>
</intent-filter>
</receiver>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
// package com.yotam17.ori.bc_to;
public class MainActivity extends AppCompatActivity {
private static final String BC_ACTION = "com.yotam17.ori.bc.Broadcast";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Register MyReceiver
IntentFilter filter = new IntentFilter(BC_ACTION);
MyReceiver receiver = new MyReceiver();
registerReceiver(receiver, filter); //<<<<<< Does not work w/o this
}
}
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Got it!!!" , Toast.LENGTH_SHORT).show();
}
}
를 사용하여 명시 적으로'Intent' (예 : 여기에 수정 된 전송은() 코드 -
는 작동 예를 만들려면 //developer.android.com/reference/android/content/Intent.html#setComponent(android.content.ComponentName))), 암시적인'Intent '가 아닙니다. – CommonsWare