List of usage examples for android.content IntentFilter addAction
public final void addAction(String action)
From source file:com.guangyao.bluetoothtest.service.BluetoothLeService.java
@Override public void onCreate() { super.onCreate(); sendDataToBleReceiver = new SendDataToBleReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(BleConstans.ACTION_SEND_DATA_TO_BLE); LocalBroadcastManager.getInstance(this).registerReceiver(sendDataToBleReceiver, intentFilter); //??/*from w ww. j a va 2 s . c o m*/ IntentFilter filter = new IntentFilter(); filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED); this.registerReceiver(bluetoothStatusChangeReceiver, filter); }
From source file:com.atlas.mars.weatherradar.MainActivity.java
private void onCreateMyReceiver() { /* if(myReceiver!=null){ unregisterReceiver(myReceiver);//from w ww . java2s. c om }*/ myReceiver = new MyReceiver(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(LOCATION); registerReceiver(myReceiver, intentFilter); }
From source file:com.example.sans.myapplication.Utility.Map.MapsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); shares = getSharedPreferences("SHARES", 0); controller = (AppController) getApplication(); receiver = new MyReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction("android.intent.action.test"); this.registerReceiver(receiver, filter); Intent i = getIntent();/*from www.j av a2 s . com*/ Bundle bundle = i.getExtras(); try { j = new JSONObject(bundle.getString("data", "ERROR")); shares.edit().putString("ORDER", bundle.getString("data", "ERROR")).commit(); } catch (JSONException e) { try { j = new JSONObject(shares.getString("ORDER", "ERROR")); } catch (JSONException e1) { SharedPreferences.Editor editor = shares.edit(); final Client client = new Client(); RequestParams params = new RequestParams(); params.put("id", shares.getInt("ID", 0)); params.put("status", 999); client.post("driver/setStatus", params, new JsonHttpResponseHandler()); editor.putBoolean("ONLINE", false); editor.putBoolean("LOGIN", false); editor.commit(); Intent intent = getApplicationContext().getPackageManager() .getLaunchIntentForPackage(getApplicationContext().getPackageName()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } } try { Log.e("PHONE_NO", String.valueOf(j.getJSONObject("passenger_data"))); } catch (JSONException e) { e.printStackTrace(); } pass_phone = (ImageView) findViewById(R.id.pass_phone); pass_phone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent phoneIntent = null; try { phoneIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:" + j.getJSONObject("passenger_data").getString("tel"))); } catch (JSONException e) { e.printStackTrace(); } startActivity(phoneIntent); } }); pass_msg = (ImageView) findViewById(R.id.pass_msg); pass_msg.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent msgIntent = new Intent(Intent.ACTION_VIEW); try { msgIntent.setData(Uri.parse("sms:" + j.getJSONObject("passenger_data").getString("tel"))); } catch (JSONException e) { e.printStackTrace(); } startActivity(msgIntent); } }); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); TextView actionBarTitle = (TextView) toolbar.findViewById(R.id.action_bar_title); try { actionBarTitle.setText(j.getJSONObject("passenger_data").getString("family_name") + j.getJSONObject("passenger_data").getString("title")); } catch (JSONException e) { e.printStackTrace(); } setUpMapIfNeeded(); navigationView = (NavigationView) findViewById(R.id.navigation_view); header = navigationView.inflateHeaderView(R.layout.header); JSONObject driver_data = null; try { driver_data = new JSONObject(shares.getString("DRIVER_DATA", "ERROR")); } catch (JSONException e) { e.printStackTrace(); } TextView driver_name_header = (TextView) header.findViewById(R.id.username); TextView car_id_header = (TextView) header.findViewById(R.id.car_id); final ImageView pp_header = (ImageView) header.findViewById(R.id.profile_image); try { car_id_header.setText(driver_data.getString("license")); driver_name_header.setText(driver_data.getString("name")); Client client = new Client(); client.get(driver_data.getString("image"), new FileAsyncHttpResponseHandler(MapsActivity.this.getApplicationContext()) { @Override public void onFailure(int i, Header[] headers, Throwable throwable, File file) { } @Override public void onSuccess(int statusCode, Header[] headers, final File response) { MapsActivity.this.runOnUiThread(new Runnable() { @Override public void run() { Bitmap image = BitmapFactory.decodeFile(response.getPath()); pp_header.setImageBitmap(image); } }); } }); } catch (JSONException e) { e.printStackTrace(); } header.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(MapsActivity.this, MenuItemActivity.class); i.putExtra("MENU_ITEM", 0); MapsActivity.this.startActivity(i); drawerLayout.closeDrawers(); } }); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { // This method will trigger on item Click of navigation menu @Override public boolean onNavigationItemSelected(MenuItem menuItem) { //Checking if the item is in checked state or not, if not make it in checked state nav = true; menuItem.setChecked(false); //Closing drawer on item click drawerLayout.closeDrawers(); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Fragment fragment; //Check to see which item was being clicked and perform appropriate action switch (menuItem.getItemId()) { case R.id.timetable: case R.id.service: case R.id.history: case R.id.mission: case R.id.points: case R.id.notice: Intent i = new Intent(MapsActivity.this, MenuItemActivity.class); i.putExtra("MENU_ITEM", menuItem.getItemId()); MapsActivity.this.startActivity(i); break; case R.id.login: //Toast.makeText(getApplicationContext(), "Logout Selected", Toast.LENGTH_SHORT).show(); SharedPreferences.Editor editor = shares.edit(); final Client client = new Client(); RequestParams params = new RequestParams(); params.put("id", shares.getInt("ID", 0)); params.put("status", 999); client.post("driver/setStatus", params, new JsonHttpResponseHandler()); editor.putBoolean("ONLINE", false); editor.putBoolean("LOGIN", false); editor.commit(); Intent intent = getApplicationContext().getPackageManager() .getLaunchIntentForPackage(getApplicationContext().getPackageName()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); break; default: //Toast.makeText(getApplicationContext(),"Somethings Wrong",Toast.LENGTH_SHORT).show(); break; } return false; } }); // Initializing Drawer Layout and ActionBarToggle drawerLayout = (DrawerLayout) findViewById(R.id.drawer); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.openDrawer, R.string.closeDrawer) { @Override public void onDrawerClosed(View drawerView) { // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank super.onDrawerClosed(drawerView); drawerLayout.setSelected(false); } @Override public void onDrawerOpened(View drawerView) { // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank super.onDrawerOpened(drawerView); } }; //Setting the actionbarToggle to drawer layout drawerLayout.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessay or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); }
From source file:com.umeng.message.example.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); pushDao = PushDao.getInstance(this); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); screenWidth = dm.widthPixels;/*from ww w . j a va2 s .c o m*/ setContentView(R.layout.activity_main); printKeyValue(); mPushAgent = PushAgent.getInstance(this); mPushAgent.onAppStart(); mPushAgent.enable(MyApplication.mRegisterCallback); tvStatus = (TextView) findViewById(R.id.tvStatus); btnEnable = (ImageView) findViewById(R.id.btnEnable); btnaAddTag = (Button) findViewById(R.id.btnAddTags); btnAddAlias = (Button) findViewById(R.id.btnAddAlias); btnListTag = (Button) findViewById(R.id.btnListTags); infoTextView = (TextView) findViewById(R.id.info); edTag = (EditText) findViewById(R.id.edTag); edAlias = (EditText) findViewById(R.id.edAlias); edAliasType = (EditText) findViewById(R.id.edAliasType); spAliasType = (Spinner) findViewById(R.id.spAliasType); edAliasType.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { edAliasTypeFocus = true; } else { edAliasTypeFocus = false; } } }); edAliasType.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub if (edAliasTypeFocus) { spAliasType.setSelection(0); } } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); String[] aliasType = new String[] { "Alias Type:", ALIAS_TYPE.SINA_WEIBO, ALIAS_TYPE.BAIDU, ALIAS_TYPE.KAIXIN, ALIAS_TYPE.QQ, ALIAS_TYPE.RENREN, ALIAS_TYPE.TENCENT_WEIBO, ALIAS_TYPE.WEIXIN }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, aliasType); spAliasType.setAdapter(adapter); spAliasType.setBackgroundColor(Color.LTGRAY); spAliasType.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub TextView tv = (TextView) arg1; if (tv != null) { int rate = (int) (5.0f * (float) screenWidth / 320.0f); int textSize = rate < 15 ? 15 : rate; tv.setTextSize((float) textSize); } if (arg2 != 0) { String type = (String) spAliasType.getItemAtPosition(arg2); edAliasType.setText(type); } else if (!edAliasTypeFocus) { edAliasType.setText(""); } } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); tvStatus.setOnClickListener(clickListener); btnEnable.setOnClickListener(clickListener); btnaAddTag.setOnClickListener(clickListener); btnListTag.setOnClickListener(clickListener); btnAddAlias.setOnClickListener(clickListener); updateStatus(); mPushAgent.setPushIntentServiceClass(MyPushIntentService.class); callbackReceiver = new CallbackReceiver(); IntentFilter filter = new IntentFilter(); filter.addAction(MyApplication.CALLBACK_RECEIVER_ACTION); registerReceiver(callbackReceiver, filter); }
From source file:com.alibaba.weex.commons.AbsWeexActivity.java
public void registerBroadcastReceiver(BroadcastReceiver receiver, IntentFilter filter) { mBroadcastReceiver = receiver != null ? receiver : new DefaultBroadcastReceiver(); if (filter == null) { filter = new IntentFilter(); }//from ww w . j a va 2 s . c o m filter.addAction(IWXDebugProxy.ACTION_DEBUG_INSTANCE_REFRESH); filter.addAction(WXSDKEngine.JS_FRAMEWORK_RELOAD); LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(mBroadcastReceiver, filter); if (mReloadListener == null) { setReloadListener(new WxReloadListener() { @Override public void onReload() { createWeexInstance(); renderPage(); } }); } if (mRefreshListener == null) { setRefreshListener(new WxRefreshListener() { @Override public void onRefresh() { createWeexInstance(); renderPage(); } }); } }
From source file:com.alivenet.dmvtaxi.fragment.FragmentArriveDriver.java
public void DataUpdateBackgroundService() { final BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.mipmap.car); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("update_map1"); deliveryBroadcastReceiver = new BroadcastReceiver() { @Override//from w w w.j a v a 2 s . com public void onReceive(Context context, Intent intent) { //TODO map updations work here System.out.println("update run FragmentArrive"); mDriverdetailsList = (ArrayList<Driverdetails>) intent.getSerializableExtra("backgroundArraylist"); // System.out.println("mDriverdetailsList info===>>>>"+mDriverdetailsList+mDriverdetailsList.size()); if (mDriverdetailsList != null) { System.out.println("mDriverdetailsList infoarrive===>>>>" + mDriverdetailsList + mDriverdetailsList.size()); for (int j = 0; j < mDriverdetailsList.size(); j++) { if (mDriverdetailsList.get(j).getDriverdetailslocations() != null && mDriverdetailsList.get(j).getDriverdetailslocations().size() > 0) { String lat = ""; String lng = ""; for (int i = 0; i < mDriverdetailsList.get(j).getDriverdetailslocations().size(); i++) { if (MyApplication.driverId != null && !MyApplication.driverId.equals("") && MyApplication.driverId.equals(mDriverdetailsList.get(j).getDriverId())) { System.out.println("ArriveDriver" + MyApplication.driverId); lat = mDriverdetailsList.get(j).getDriverdetailslocations().get(i) .getLatitude(); lng = mDriverdetailsList.get(j).getDriverdetailslocations().get(i) .getLongitude(); validateGET_TIME(latitude, longitude, Double.parseDouble(lat), Double.parseDouble(lng)); if (marker != null) { System.out.println("ArriveDriver" + "ifunder>>>>>>>>>>>>>>>>>>>>>"); marker.setPosition( new LatLng(Double.parseDouble(lat), Double.parseDouble(lng))); angle = (float) finalBearing(previousLocationLatitude, previousLocationLongitude, Double.parseDouble(lat), Double.parseDouble(lng)); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(previousLocationLatitude, previousLocationLongitude)) .bearing(angle).tilt(90).zoom(15).build(); googleMap.animateCamera( CameraUpdateFactory.newCameraPosition(cameraPosition)); previousLocationLatitude = Double.parseDouble(lat); previousLocationLongitude = Double.parseDouble(lng); } else { System.out.println("ArriveDriver" + "elseunder>>>>>>>>>>>>>>>>>>>>>"); marker = googleMap.addMarker(markerOptions.icon(icon).position(new LatLng( Double.parseDouble(mDriverdetailsList.get(j) .getDriverdetailslocations().get(i).getLatitude()), Double.parseDouble(mDriverdetailsList.get(j) .getDriverdetailslocations().get(i).getLongitude()))) .draggable(true).visible(true)); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(previousLocationLatitude, previousLocationLongitude)) .bearing(angle).tilt(90).zoom(15).build(); googleMap.animateCamera( CameraUpdateFactory.newCameraPosition(cameraPosition)); previousLocationLatitude = Double.parseDouble(mDriverdetailsList.get(j) .getDriverdetailslocations().get(i).getLatitude()); previousLocationLongitude = Double.parseDouble(mDriverdetailsList.get(j) .getDriverdetailslocations().get(i).getLongitude()); } } } } } } } }; getActivity().registerReceiver(deliveryBroadcastReceiver, intentFilter); }
From source file:com.notalenthack.blaster.CommandActivity.java
private void setupFilter() { final IntentFilter filter = new IntentFilter(); filter.addAction(Constants.ACTION_REFRESH_STATUS); mReceiver = new BroadcastReceiver() { @Override/*from w ww. ja v a2 s . c o m*/ public void onReceive(Context context, Intent intent) { // Got intent to clean up if (intent.getAction().equals(Constants.ACTION_REFRESH_STATUS)) { if (D) Log.d(TAG, "onReceive intent " + intent.toString()); List<Command> commands = mListAdapter.getCommands(); // this list should be in the same order as in the ListBox int i = 0; for (Command cmd : commands) { if (cmd.getDisplayStatus()) { mSerialService.sendStatusCommand(cmd.getCommandStat(), i, false); } i++; } } } }; registerReceiver(mReceiver, filter); }
From source file:com.android.music.AlbumBrowserFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view = inflater.inflate(R.layout.media_picker_activity, null); if (savedInstanceState != null) { mCurrentAlbumId = savedInstanceState.getString("selectedalbum"); mArtistId = savedInstanceState.getString("artist"); } else {// w w w . j a va2 s . c om mArtistId = getActivity().getIntent().getStringExtra("artist"); } //getActivity().requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); //requestWindowFeature(Window.FEATURE_NO_TITLE); getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC); mToken = MusicUtils.bindToService(getActivity(), this); IntentFilter f = new IntentFilter(); f.addAction(Intent.ACTION_MEDIA_SCANNER_STARTED); f.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED); f.addAction(Intent.ACTION_MEDIA_UNMOUNTED); f.addDataScheme("file"); getActivity().registerReceiver(mScanListener, f); lv = (ListView) view.findViewById(android.R.id.list); lv.setOnCreateContextMenuListener(this); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(this); mAdapter = (AlbumListAdapter) getActivity().getLastNonConfigurationInstance(); if (mAdapter == null) { //Log.i("@@@", "starting query"); mAdapter = new AlbumListAdapter(getActivity().getApplication(), this, R.layout.track_list_item, mAlbumCursor, new String[] {}, new int[] {}); lv.setAdapter(mAdapter); //getActivity().setTitle(R.string.working_albums); getAlbumCursor(mAdapter.getQueryHandler(), null); } else { mAdapter.setActivity(this); lv.setAdapter(mAdapter); mAlbumCursor = mAdapter.getCursor(); if (mAlbumCursor != null) { init(mAlbumCursor); } else { getAlbumCursor(mAdapter.getQueryHandler(), null); } } return view; }
From source file:dk.ciid.android.infobooth.activities.IntroductionActivity.java
@Override public void onCreate(Bundle savedInstanceState) { /* Variables received through Intent */ Intent openActivity = getIntent(); // this is just for example purpose isInDebugMode = openActivity.getBooleanExtra("isInDebugMode", true); // should the app send a welcome sms after subscribing? voice1 = openActivity.getStringExtra("voice1"); // path to voice file 1 voice2 = openActivity.getStringExtra("voice2"); // path to voice file 2 voice3 = openActivity.getStringExtra("voice3"); // path to voice file 3 voice4 = openActivity.getStringExtra("voice4"); // path to voice file 4 voice5 = openActivity.getStringExtra("voice5"); // path to voice file 5 voice6 = openActivity.getStringExtra("voice6"); // path to voice file 6 /* Variables received through Intent */ super.onCreate(savedInstanceState); /* ARDUINO COMMUNICATION STUFF ********************************************/ // a reference to the USB system service is obtained so that you can call its methods later on mUsbManager = UsbManager.getInstance(this); mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED); registerReceiver(mUsbReceiver, filter); if (getLastNonConfigurationInstance() != null) { mAccessory = (UsbAccessory) getLastNonConfigurationInstance(); openAccessory(mAccessory);//ww w .ja v a2 s .c om } /* ARDUINO COMMUNICATION STUFF ********************************************/ gestureScanner = new GestureDetector(this); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_introduction); // Set up sound playback initMediaPlayer(); runOnUiThread(new Runnable() { public void run() { if (isInDebugMode) Toast.makeText(getApplicationContext(), "Debug mode is ON", Toast.LENGTH_SHORT).show(); } }); }
From source file:com.amazon.android.contentbrowser.helper.AuthHelper.java
/** * Constructor.//from w w w . java 2 s.c o m * * @param context Context. * @param contentBrowser Content browser. */ public AuthHelper(Context context, ContentBrowser contentBrowser) { mAppContext = context.getApplicationContext(); mContentBrowser = contentBrowser; // Get default Auth interface without creating a new one. try { mIAuthentication = (IAuthentication) ModuleManager.getInstance() .getModule(IAuthentication.class.getSimpleName()).getImpl(true); } catch (Exception e) { Log.e(TAG, "No Auth Interface interface attached.", e); } IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(LogoutSettingsFragment.LOGOUT_BUTTON_BROADCAST_INTENT_ACTION); LocalBroadcastManager.getInstance(mAppContext).registerReceiver(mLocalBroadcastReceiver, intentFilter); //AuthHelper is initialized, broadcast initial authentication status isAuthenticated().subscribe(isAuthenticatedResultBundle -> { boolean result = isAuthenticatedResultBundle.getBoolean(AuthHelper.RESULT); broadcastAuthenticationStatus(result); }); }