當前位置: 首頁>>代碼示例>>Java>>正文


Java BroadcastReceiver類代碼示例

本文整理匯總了Java中android.content.BroadcastReceiver的典型用法代碼示例。如果您正苦於以下問題:Java BroadcastReceiver類的具體用法?Java BroadcastReceiver怎麽用?Java BroadcastReceiver使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BroadcastReceiver類屬於android.content包,在下文中一共展示了BroadcastReceiver類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onNewNotification

import android.content.BroadcastReceiver; //導入依賴的package包/類
/**
 * Gets notifications from other apps.
 * In order to work to must enable the access of notifications in your device settings
 *
 * @param callback
 * @status TOREVIEW
 */
@ProtoMethod
public void onNewNotification(final ReturnInterface callback) {
    if (!isNotificationServiceRunning()) {
        showNotificationsManager();
    }

    onNotification = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            ReturnObject ret = new ReturnObject();

            ret.put("package", intent.getStringExtra("package"));
            ret.put("title", intent.getStringExtra("title"));
            ret.put("text", intent.getStringExtra("text"));

            callback.event(ret);
        }
    };

    LocalBroadcastManager.getInstance(getContext()).registerReceiver(onNotification, new IntentFilter("Msg"));
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:29,代碼來源:PDevice.java

示例2: unregisterReceiver

import android.content.BroadcastReceiver; //導入依賴的package包/類
/**
 * unregisterReceiver
 *
 * @param loaded mLoaded
 */
public static void unregisterReceiver(ApkLoaded loaded) {
    String key = loaded.getApkPath();
    if (!CONTEXT_MAP.containsKey(key)) {
        return;
    }
    Context context = CONTEXT_MAP.get(key);
    if (BROADCAST_RECEIVER_MAP.containsKey(key)) {
        LinkedList<BroadcastReceiver> receivers = BROADCAST_RECEIVER_MAP.get(key);
        for (int i = 0; i < receivers.size(); i++) {
            context.unregisterReceiver(receivers.get(i));
        }
        BROADCAST_RECEIVER_MAP.remove(key);
    }
    CONTEXT_MAP.containsKey(key);
}
 
開發者ID:LiangMaYong,項目名稱:android-apkbox,代碼行數:21,代碼來源:ApkReceiver.java

示例3: newBroadcastReceiver

import android.content.BroadcastReceiver; //導入依賴的package包/類
@CheckResult
private BroadcastReceiver newBroadcastReceiver() {
    return new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            switch (intent.getAction()) {
                case ServiceAction.HIDE:
                    resetViewParams(mHideParams);
                    break;

                case ServiceAction.SHOW:
                    resetViewParams(mParams);
                    break;

                case ServiceAction.STOP:
                    stopSelf();
                    break;

                case ServiceAction.START:
                default:
                    throw new IllegalStateException();
            }
        }
    };
}
 
開發者ID:RollnCode,項目名稱:BackTube,代碼行數:26,代碼來源:PlayerService.java

示例4: registMyRecivier

import android.content.BroadcastReceiver; //導入依賴的package包/類
private void registMyRecivier()
    {
        filter = new IntentFilter(Constant.REENTER);
        mReceiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {

                String action = intent.getAction();
                if(action.equals(Constant.REENTER))
                {
                    LogUtil.d("dfy","收到重新登錄的請求");
                    isNeedJump = false;
//                    LogUtil.d("dfy","loginBiz = "+loginBiz);
                    loginBiz = null;
                    loginBiz = new LoginBiz(loginInstance);
//                    LogUtil.d("dfy","loginBiz = "+loginBiz);
                    login();
                }
            }
        };
    }
 
開發者ID:dufangyu1990,項目名稱:LeCatApp,代碼行數:23,代碼來源:LoginActivity.java

示例5: RegisterActivity

import android.content.BroadcastReceiver; //導入依賴的package包/類
public RegisterActivity() {
    if (HotFix.PREVENT_VERIFY) {
        System.out.println(VerifyLoad.class);
    }
    this.recever = new BroadcastReceiver(this) {
        final /* synthetic */ RegisterActivity this$0;

        {
            if (HotFix.PREVENT_VERIFY) {
                System.out.println(VerifyLoad.class);
            }
            this.this$0 = this$0;
        }

        public void onReceive(Context arg0, Intent arg1) {
            this.this$0.finish();
        }
    };
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:20,代碼來源:RegisterActivity.java

示例6: onResume

import android.content.BroadcastReceiver; //導入依賴的package包/類
@Override
protected void onResume() {
    super.onResume();
    IntentFilter filter = new IntentFilter();
    filter.addAction("FINISH_ACTIVITY");
    receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if(isAboveLolipop) {
                finishAndRemoveTask();
            } else {
                finish();
            }
        }
    };
    registerReceiver(receiver, filter);
}
 
開發者ID:ceanyd,項目名稱:react-native-caller-id-android,代碼行數:18,代碼來源:InCall.java

示例7: initialize

import android.content.BroadcastReceiver; //導入依賴的package包/類
/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 *
 * @param cordova The context of the main Activity.
 * @param webView The CordovaWebView Cordova is running in.
 */
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    this.connectionCallbackContext = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                // (The null check is for the ARM Emulator, please use Intel Emulator for better results)
                if(NetworkManager.this.webView != null)
                    updateConnectionInfo(sockMan.getActiveNetworkInfo());
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }

}
 
開發者ID:SUTFutureCoder,項目名稱:localcloud_fe,代碼行數:29,代碼來源:NetworkManager.java

示例8: initOutgoingBroadcastReceiver

import android.content.BroadcastReceiver; //導入依賴的package包/類
/**
 * Broadcast receiver to check outgoing call
 */
private void initOutgoingBroadcastReceiver() {
    OutgoingBroadcastReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {

            if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {

                isInCall = true;

                if (isInCall == true) {
                    smallMediaPlayer = SmallMediaPlayer.getInstance(context);
                    bigNotification = false;
                    pauseMedia();
                }

            }
        }
    };
    IntentFilter filter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
    context.registerReceiver(OutgoingBroadcastReceiver, filter);
}
 
開發者ID:fekracomputers,項目名稱:QuranAndroid,代碼行數:26,代碼來源:AudioManager.java

示例9: callPvDataService

import android.content.BroadcastReceiver; //導入依賴的package包/類
private void callPvDataService() {
    BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            LocalBroadcastManager.getInstance(context).unregisterReceiver(this);
            if (intent.getBooleanExtra("success", true)) {
                updateScreen();
            } else {
                Toast.makeText(context, intent.getStringExtra("message"),
                        Toast.LENGTH_LONG).show();
            }
        }
    };
    IntentFilter intentFilter = new IntentFilter(PvDataService.class.getName());
    LocalBroadcastManager.getInstance(getContext())
            .registerReceiver(broadcastReceiver, intentFilter);

    PvDataService.callLive(getContext(), picked.year, picked.month, picked.day);
}
 
開發者ID:jansipke,項目名稱:pvdisplay,代碼行數:20,代碼來源:LiveFragment.java

示例10: defineBroadcastReceiverFor

import android.content.BroadcastReceiver; //導入依賴的package包/類
private BroadcastReceiver defineBroadcastReceiverFor(final FlowableEmitter<SensorRecord> subscriber){
    return new BroadcastReceiver() {
        Timer timer = new Timer();
        long prevCallTime = new Date().getTime();

        @Override
        public void onReceive(Context context, Intent intent) {
            long actualTime = new Date().getTime();
            long delay = calculateDiffDelay(prevCallTime, actualTime);
            prevCallTime = actualTime;

            subscriber.onNext(new WifiMeasurementsRecord(wifiManager.getScanResults()));

            if (delay > 0)
                timer.schedule(createScanTask(), delay);
            else
                createScanTask().run();
        }
    };
}
 
開發者ID:ubikgs,項目名稱:AndroidSensors,代碼行數:21,代碼來源:WifiMeasurementsGatherer.java

示例11: onCreateView

import android.content.BroadcastReceiver; //導入依賴的package包/類
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View mView = inflater.inflate(R.layout.seal_mine_fragment, container, false);
    isDebug = getContext().getSharedPreferences("config", getContext().MODE_PRIVATE).getBoolean("isDebug", false);
    initViews(mView);
    initData();
    //設置廣播接收者  更新用戶頭像和昵稱
    BroadcastManager.getInstance(getActivity()).addAction(SealConst.CHANGEINFO, new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            updateUserInfo();
        }
    });
    compareVersion();
    return mView;
}
 
開發者ID:LanguidSheep,項目名稱:sealtalk-android-master,代碼行數:18,代碼來源:MineFragment.java

示例12: initBroadcastReceiver

import android.content.BroadcastReceiver; //導入依賴的package包/類
/**
 * 注冊廣播接收者
 */
private void initBroadcastReceiver() {
    mBroadcastManager = LocalBroadcastManager.getInstance(getActivity());
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(AppDelegate.ACTION_T_FINANCING_ACCOUNT_SEARCH);
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            arguments = intent.getStringExtra(AppDelegate.ACTION_T_ACCOUNT_SEARCH);

            // 更新數據
            pageIndex = 1;
            isFirstLoading = true;
            onBackgrounds();
        }
    };
    mBroadcastManager.registerReceiver(mReceiver, intentFilter);

}
 
開發者ID:jpaijh,項目名稱:TYT,代碼行數:22,代碼來源:T_MyFund_AccountFinancingFragment.java

示例13: onResume

import android.content.BroadcastReceiver; //導入依賴的package包/類
@Override
protected void onResume() {
    super.onResume();
    // registramos un broadcast receiver
    tickReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().compareTo(Intent.ACTION_TIME_TICK) == 0) {
                tvHour.setText(getHour());
                tvMinute.setText(getMinute());
            }
        }
    };
    registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
    if (!set.isRunning()) {
        set.start();
    }
}
 
開發者ID:gothalo,項目名稱:Android-2017,代碼行數:19,代碼來源:TimerActivity.java

示例14: addStateListener

import android.content.BroadcastReceiver; //導入依賴的package包/類
private void addStateListener() {
    if (this.stateReceiver == null) {
        this.stateReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                onBluetoothStateChange(intent);
            }
        };
    }

    try {
        IntentFilter intentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
        webView.getContext().registerReceiver(this.stateReceiver, intentFilter);
    } catch (Exception e) {
        LOG.e(TAG, "Error registering state receiver: " + e.getMessage(), e);
    }
}
 
開發者ID:disit,項目名稱:siiMobilityAppKit,代碼行數:18,代碼來源:BLECentralPlugin.java

示例15: observeChanges

import android.content.BroadcastReceiver; //導入依賴的package包/類
@Override
public Observable<Integer> observeChanges() {
    return Observable.create(e -> {
        BroadcastReceiver receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (nonNull(intent) && WHAT_ACCOUNT_CHANGE.equals(intent.getAction())) {
                    e.onNext(intent.getExtras().getInt(Extra.ACCOUNT_ID));
                }
            }
        };

        e.setCancellable(() -> LocalBroadcastManager.getInstance(app).unregisterReceiver(receiver));
        if (!e.isDisposed()) {
            LocalBroadcastManager.getInstance(app).registerReceiver(receiver, new IntentFilter(WHAT_ACCOUNT_CHANGE));
        }
    });
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:19,代碼來源:AccountsSettings.java


注:本文中的android.content.BroadcastReceiver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。