List of usage examples for android.content IntentFilter addAction
public final void addAction(String action)
From source file:com.android.managedprovisioning.ProfileOwnerProvisioningActivity.java
@Override protected void onResume() { super.onResume(); // Setup broadcast receiver for feedback from service. mServiceMessageReceiver = new ServiceMessageReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction(ProfileOwnerProvisioningService.ACTION_PROVISIONING_SUCCESS); filter.addAction(ProfileOwnerProvisioningService.ACTION_PROVISIONING_ERROR); filter.addAction(ProfileOwnerProvisioningService.ACTION_PROVISIONING_CANCELLED); LocalBroadcastManager.getInstance(this).registerReceiver(mServiceMessageReceiver, filter); // Start service async to make sure the UI is loaded first. final Handler handler = new Handler(getMainLooper()); handler.post(new Runnable() { @Override//from ww w .j av a 2s .c o m public void run() { Intent intent = new Intent(ProfileOwnerProvisioningActivity.this, ProfileOwnerProvisioningService.class); intent.putExtras(getIntent()); startService(intent); } }); }
From source file:com.gao.im.ui.ECSuperActivity.java
protected final void registerReceiver(String[] actionArray) { if (actionArray == null) { return;// w ww . j a v a 2 s .c o m } IntentFilter intentfilter = new IntentFilter(); for (String action : actionArray) { intentfilter.addAction(action); } if (internalReceiver == null) { internalReceiver = new InternalReceiver(); } registerReceiver(internalReceiver, intentfilter); }
From source file:com.ironsmile.cordova.mediaevents.MediaEventListener.java
/** * Executes the request./*from ww w. j av a 2s . c om*/ * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context used when calling back into js * @return True if the action was valid, false if not. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("start")) { if (this.eventCallbackContext != null) { callbackContext.error("Media event listener already running."); return true; } this.eventCallbackContext = callbackContext; // We need to listen to audio events IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { sendMediaEvent(intent); } }; cordova.getActivity().registerReceiver(this.receiver, intentFilter); } if (this.focusListener == null) { Context ctx = cordova.getActivity().getBaseContext(); this.focusListener = this.new FocusListener(ctx); } // Don't return any result now, since status results will be sent when // events come in from broadcast receiver PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); return true; } else if (action.equals("stop")) { removeMediaEventListener(); // release status callback in JS side this.sendUpdate(new JSONObject(), false); this.eventCallbackContext = null; callbackContext.success(); return true; } return false; }
From source file:com.manuelmazzuola.speedtogglebluetooth.service.MonitorSpeed.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { running = Boolean.TRUE;// w ww.ja v a2 s . co m lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); provider = lm.NETWORK_PROVIDER; oldLocation = lm.getLastKnownLocation(provider); IntentFilter filters = new IntentFilter(); // When to turn off bluetooth filters.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED); // When hold bluetooth on filters.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); // When user directly turn on or off bluetooth filters.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); registerReceiver(bluetoothListener, filters); lm.requestLocationUpdates(provider, 45 * 1000, 0f, this); Intent stopIntent = new Intent(this, MainActivity.class); stopIntent.putExtra("close", "close"); PendingIntent stopPendingIntent = PendingIntent.getActivity(this, 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder note = new NotificationCompat.Builder(getApplicationContext()) .setContentTitle(DEFAULT_TITLE).setContentText(DEFAULT_MESSAGE) .setDefaults(Notification.DEFAULT_VIBRATE).setAutoCancel(true).setContentIntent(stopPendingIntent) .setSmallIcon(R.drawable.ic_action_bluetooth); note.getNotification().flags |= Notification.FLAG_AUTO_CANCEL; Notification notification = note.build(); notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; startForeground(intentId, note.build()); return START_NOT_STICKY; }
From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.FixturesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fixtures_layout, container, false); ButterKnife.inject(this, view); buildGoogleApiClient();/* w w w .j av a 2s .co m*/ //Registering events to detect radio changes final BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { updateBluetoothStatusDisplay(); } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { updateWifiStatusDisplay(); } else if (action.equals(LocationManager.PROVIDERS_CHANGED_ACTION)) { updateGPSStatusDisplay(); } else if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) { updateNFCStatusDisplay(); } } }; IntentFilter filter = new IntentFilter(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { filter.addAction(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED); } filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); filter.addAction(LocationManager.PROVIDERS_CHANGED_ACTION); updateWifiStatusDisplay(); updateBluetoothStatusDisplay(); updateGPSStatusDisplay(); updateNFCStatusDisplay(); getActivity().registerReceiver(receiver, filter); return view; }
From source file:com.android.tv.settings.device.storage.FormatActivity.java
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPackageManager = getPackageManager(); mStorageManager = getSystemService(StorageManager.class); final IntentFilter filter = new IntentFilter(); filter.addAction(SettingsStorageService.ACTION_FORMAT_AS_PRIVATE); filter.addAction(SettingsStorageService.ACTION_FORMAT_AS_PUBLIC); LocalBroadcastManager.getInstance(this).registerReceiver(mFormatReceiver, filter); if (savedInstanceState != null) { mFormatAsPrivateDiskId = savedInstanceState.getString(SAVE_STATE_FORMAT_PRIVATE_DISK_ID); mFormatAsPublicDiskId = savedInstanceState.getString(SAVE_STATE_FORMAT_PUBLIC_DISK_ID); mFormatDiskDesc = savedInstanceState.getString(SAVE_STATE_FORMAT_DISK_DESC); } else {/*w w w . j a v a2 s . c o m*/ final String diskId = getIntent().getStringExtra(DiskInfo.EXTRA_DISK_ID); final String action = getIntent().getAction(); final Fragment f; if (TextUtils.equals(action, INTENT_ACTION_FORMAT_AS_PRIVATE)) { f = FormatAsPrivateStepFragment.newInstance(diskId); } else if (TextUtils.equals(action, INTENT_ACTION_FORMAT_AS_PUBLIC)) { f = FormatAsPublicStepFragment.newInstance(diskId); } else { throw new IllegalStateException("No known action specified"); } getFragmentManager().beginTransaction().add(android.R.id.content, f).commit(); } }
From source file:com.eggwall.SoundSleep.SleepActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Go full screen. if (SDK >= 11) { (getActionBar()).hide();/*from ww w. java 2 s .co m*/ } else { requestWindowFeature(Window.FEATURE_NO_TITLE); } final int fullscreen = WindowManager.LayoutParams.FLAG_FULLSCREEN; getWindow().setFlags(fullscreen, fullscreen); setContentView(R.layout.main); postClockChange(INITIAL_DELAY); setGlobalScreenSettings(); final LocalBroadcastManager m = LocalBroadcastManager.getInstance(this); final IntentFilter filter = new IntentFilter(); filter.addAction(AudioService.MESSAGE_SILENCE); filter.addAction(AudioService.MESSAGE_MUSIC); filter.addAction(AudioService.MESSAGE_WHITE_NOISE); m.registerReceiver(mMessageReceiver, filter); if (savedInstanceState != null) { mState = savedInstanceState.getInt(STATE_KEY, AudioService.SILENCE); } // Ask the service for the current state. It will send a broadcast with the current state. sendRequest(AudioService.GET_STATUS); }
From source file:com.google.android.gms.samples.vision.face.facetracker.MainActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override/*w w w . j a v a 2s .c om*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mainactivity); // ---Ambil username dari sharedpreference agar user tetap dapat melihat schedule jika keluar dari apps------ sharedPreferences = getSharedPreferences("PHAROS", MODE_PRIVATE); username = sharedPreferences.getString("Username", ""); // --------------------------------------------------------------------------------------------------------- // ---Deklarasi fragment fragment yang akan di gunakan--- Fragment CameraFragment = new CameraFragment(); Fragment LoginFramgent = new LoginFragment(); Fragment ScheduleFragment = new ScheduleFragment(); // ----------------------------------------------------- // Meminta permisssion untuk GPS jika menggunakan android Marshmallow keatas if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && checkSelfPermission( android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { requestPermissions(new String[] { android.Manifest.permission.ACCESS_COARSE_LOCATION }, 1); } // ------------------------------------------------------------------------- // ------- Instantiasi intent filter untuk broadcast recevier------ IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); IntentFilter connectionIntentFilter = new IntentFilter(); connectionIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); // --------------------------------------------------------------------- wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); wifiConfiguration = new WifiConfiguration(); // Registrasikan broadcast receiver registerReceiver(new wifiEnabled(wifiManager), intentFilter); registerReceiver(new wifiConnecting(wifiManager), connectionIntentFilter); // --------------------------------------- // -------- Deklarasi view pager--------- viewPager = (ViewPager) findViewById(R.id.fragmentFrame); pagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager(), CameraFragment, LoginFramgent, ScheduleFragment); viewPager.setAdapter(pagerAdapter); // Mengarahkan halaman awal saat membuka aplikasi ke fragment index 1 viewPager.setCurrentItem(1); // ------------------------------------- }
From source file:com.binoy.vibhinna.VibhinnaFragment.java
@Override public void onResume() { super.onResume(); IntentFilter filter = new IntentFilter(); filter.addAction(VibhinnaService.ACTION_VFS_LIST_UPDATED); mLocalBroadcastManager.registerReceiver(mBroadcastReceiver, filter); }
From source file:com.android.car.trust.CarBleTrustAgent.java
@Override public void onCreate() { super.onCreate(); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Bluetooth trust agent starting up"); }//from w w w . j a va 2 s . c om IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_REVOKE_TRUST); filter.addAction(ACTION_ADD_TOKEN); filter.addAction(ACTION_IS_TOKEN_ACTIVE); filter.addAction(ACTION_REMOVE_TOKEN); mLocalBroadcastManager = LocalBroadcastManager.getInstance(this /* context */); mLocalBroadcastManager.registerReceiver(mTrustEventReceiver, filter); // If the user is already unlocked, don't bother starting the BLE service. UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); if (!um.isUserUnlocked()) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "User locked, will now bind CarUnlockService"); } Intent intent = new Intent(this, CarUnlockService.class); bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE); } else { setManagingTrust(true); } }