Java tutorial
//package com.java2s; //License from project: Apache License import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.support.annotation.NonNull; public class Main { private static final String PERM_COMMON_BROADCAST = ".permission.COMMON_BROADCAST"; /** * Register a receiver both for internal broadcast or system broadcast. */ public static Intent register(@NonNull Context cxt, @NonNull BroadcastReceiver receiver, @NonNull IntentFilter filter) { String perm = cxt.getPackageName() + PERM_COMMON_BROADCAST; return cxt.registerReceiver(receiver, filter, perm, null); } }