在一个Apk里写了个Receiver, 然后再AndroidManifest.xml里注册
然后再另外一个apk的Activity里调用sendBroadcast, recever没启动
但是我把这个Receiver和sendBroadcast放在同一个apk里, 就能启动
不知道为什么Receiver的实现:
public class MyReceiver extends BroadcastReceiver{

NotificationManager manager = null;

@Override
public void onReceive(Context context, Intent inputIntent) {
NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "hello android", System.currentTimeMillis());

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(People.CONTENT_URI);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

notification.setLatestEventInfo(context, "click me", "test Nofification", pendingIntent);

manager.notify(1, notification);

Log.i("wyl", "onReceive " + ThreadUtils.getThreadSign());
}
}在AndroidManifist.xml里注册
        <receiver android:name=".MyReceiver" >
            <intent-filter >
                <action android:name="com.wyl.testproject.serviceRecv" />
            </intent-filter>
        </receiver>
在另外一个apk的 Activity里写
Intent intent = new Intent("com.wyl.testproject.serviceRecv"); this.sendBroadcast(intent);Receiver启动不了
放在同一个apk里就能启动
谁知道为什么

解决方案 »

  1.   

    你试试先启动receiver那个apk看看
      

  2.   

    如果你是在4.0以上版本调试的话   那LS就是正解
    4.0以后  一个未启动过至少一次的apk  是收不到任何广播的  注意这句话!!所以你可以这样做:通过包名先启动你的receiver所在的apk一次  然后发广播
     或者在你的receiver所在的apk里面加个activity  启动一次后关掉  再发送广播