0

I added receiver in manifest

<receiver android:name=".PackageReceiver"
        android:enabled="true">
        <intent-filter android:priority="100">
            <action android:name="android.intent.action.PACKAGE_ADDED"/>
            <action android:name="android.intent.action.PACKAGE_REPLACED"/>
            <data android:scheme="package"/>
        </intent-filter>  
</receiver>

And this is my BroadcastReceiver

public class PackageReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {

    Log.e("noti", "sucess");
    //Start Notification Service
    Intent i = new Intent(context, NotificationService.class);
    context.startService(i);
}}

..

When I install this package, It's didn't work...

This package don't have activity.(only service and resource)

Is this a problem?

Then..

How to call BroadcastReceiver in this package without activity?

Kara
  • 6,115
  • 16
  • 50
  • 57
Justin
  • 141
  • 11

2 Answers2

0

You have just declared and implemented a BroadcastReceiver, but you haven't started it yet, you need an entry point to start your receiver ( activity or service )

here is the code to register

PackageReceiver packageReceiver= new PackageReceiver(this);
registerReceiver( packageReceiver, new IntentFilter("android.intent.action.PACKAGE_ADDED"));
Ahmad Dwaik 'Warlock'
  • 5,953
  • 5
  • 34
  • 56
  • As there is no straigh forward way, check out the accepted answer here http://stackoverflow.com/questions/10909683/launch-android-application-without-main-activity-and-start-service-on-launching – Ahmad Dwaik 'Warlock' Apr 07 '14 at 06:27
0

This is a question that is asked a lot.

Check out this Commonsware blog.

Starting with 3.1 when applications are installed they are in a “stopped” state so they will not be able to run until the user explicitly launches them. Pressing Force Stop will return them to this state.

There needs to be an active component in your application that the user can start. When your activity gets started, your BroadcastReceiver will be registered.

Ion Aalbers
  • 7,830
  • 3
  • 37
  • 50