Can android application have only broadcast recevier and service without activity

后端 未结 2 1524
旧时难觅i
旧时难觅i 2021-01-07 02:34

Can android application have only broadcast recevier and service without activity ? If this is possible how can i invoke broadcast receiver ? Android system automatically in

相关标签:
2条回答
  • 2021-01-07 02:43

    Starting with Honeycomb, BroadcastReceivers are installed in a stopped state and will not trigger until an application has actually run, i.e. you will need an activity to have run at least once. This is explained in depth in this Commonsware blog post:

    Broadcast Regression Confirmed

    Android 3.1

    0 讨论(0)
  • 2021-01-07 02:57
    public class FlashApkclass extends BroadcastReceiver{
    
        @Override
        public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
    
         }
    }
    

    In your manifest.xml file set your android:name as like

    <receiver android:name="com.example.ambrecentral.server.FlashApkclass"
                    android:exported="false">
            <intent-filter>
             // register you broadcast receiver to list broadcast 
               <action android:name="com.example.android.APP_CLOUD_DELETE_APK"/>
            </intent-filter>
    
    </receiver>
    

    and if you want to broadcast

    broadcast.setAction(BROADCAST_ACTION);
    sendBroadcast(broadcast);
    

    where BROADCAST_ACTION is

    public static String BROADCAST_ACTION = "com.example.android.APP_CLOUD_DELETE_APK";    
    
    0 讨论(0)
提交回复
热议问题