Example usage for android.content Intent getAction

List of usage examples for android.content Intent getAction

Introduction

In this page you can find the example usage for android.content Intent getAction.

Prototype

public @Nullable String getAction() 

Source Link

Document

Retrieve the general action to be performed, such as #ACTION_VIEW .

Usage

From source file:ch.carteggio.provider.sync.NotificationService.java

protected void onHandleIntent(Intent intent) {

    if (intent != null) {

        if (UPDATE_RECEIVING_STATE_ACTION.equals(intent.getAction())) {

            mReceiveFailure = intent.getBooleanExtra(FAILURE_EXTRA, true);

            mReceiveMessage = intent.getStringExtra(FAILURE_MESSAGE_EXTRA);

            if (!mReceiveFailure) {
                mLastReceiveSuccessTime = SystemClock.elapsedRealtime();
            }/*from w w  w  . j  a v  a2 s .com*/

        } else if (UPDATE_SENDING_STATE_ACTION.equals(intent.getAction())) {

            mSendFailure = intent.getBooleanExtra(FAILURE_EXTRA, true);

            mSendMessage = intent.getStringExtra(FAILURE_MESSAGE_EXTRA);

            if (!mSendFailure) {
                mLastSendSuccessTime = SystemClock.elapsedRealtime();
            }

        } else if (UPDATE_UNREAD_STATE_ACTION.equals(intent.getAction())) {

            boolean newMessage = intent.getBooleanExtra(NEW_MESSAGE_EXTRA, false);

            updateUnreadNotification(newMessage);

        }

    }

    // update the notifications
    if ((mSendFailure && SystemClock.elapsedRealtime() - mLastSendSuccessTime > DISCONNECTION_TIME_THRESHOLD)
            || (mReceiveFailure && SystemClock.elapsedRealtime()
                    - mLastReceiveSuccessTime > DISCONNECTION_TIME_THRESHOLD)) {
        showFailureNotification();
    } else {
        hideFailureNotification();
    }

    // inform UI of the changes
    broadcastNetworkStateChange();

}

From source file:alaindc.memenguage.View.MainActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    checkLoggedIn();//from w  w  w  .j  a va 2  s.  co  m
    setContentView(R.layout.activity_main);

    dbmanager = new DBManager(getApplicationContext());
    crs = dbmanager.getAllWords();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    if (fab != null)
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent createWordIntentActivity = new Intent(MainActivity.this, CreateEditActivity.class);
                createWordIntentActivity.setAction(Constants.ACTION_ADD_WORD);
                MainActivity.this.startActivity(createWordIntentActivity);
            }
        });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    if (drawer != null)
        drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null)
        navigationView.setNavigationItemSelectedListener(this);

    ImageView navlogo = (ImageView) navigationView.getHeaderView(0).findViewById(R.id.navLogoImageView);
    TextView navtitle = (TextView) navigationView.getHeaderView(0).findViewById(R.id.navTitle);
    TextView navsubtitle = (TextView) navigationView.getHeaderView(0).findViewById(R.id.navSubTitle);
    progressDialog = new ProgressDialog(this);

    BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Constants.INTENT_VIEW_UPDATE)) {
                adapter.getFilter().filter("");
                adapter.notifyDataSetChanged();
            } else if (intent.getAction().equals(Constants.INTENT_COMMSERV_UPDATE)) {
                boolean success = intent.getBooleanExtra(Constants.EXTRA_COMMSERV_SUCCESS, false);
                String message = (intent.getIntExtra(Constants.EXTRA_COMMSERV_TYPE, 0) == Constants.UPLOAD)
                        ? "Databased uploaded "
                        : "Databased downloaded ";
                message = (success) ? message + "successfully!" : "An error occurred, try again.";
                progressDialog.setMessage(message);
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        progressDialog.dismiss();
                    }
                }, 1500);

            } else {
                Log.d("", "");
            }
        }
    };

    IntentFilter updateviewIntFilt = new IntentFilter(Constants.INTENT_VIEW_UPDATE);
    IntentFilter serverCommIntFilt = new IntentFilter(Constants.INTENT_COMMSERV_UPDATE);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, updateviewIntFilt);
    LocalBroadcastManager.getInstance(this).registerReceiver(receiver, serverCommIntFilt);

    SharedPreferences sharedPref = getApplicationContext().getSharedPreferences(Constants.PREF_FILE,
            Context.MODE_PRIVATE);
    personName = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_NAME, "");
    personEmail = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_EMAIL, "");
    personId = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_ID, "");
    personPhoto = sharedPref.getString(Constants.PREF_GOOGLEACCOUNT_PHOTOURI, "");

    //        if (!personPhoto.equals(""))
    //            new AsyncImageTask(navlogo).execute(personPhoto);
    navtitle.setText(personName);
    navsubtitle.setText(personEmail);

    // TODO Just one time and in bcast receiver start phone
    Intent randomStart = new Intent(MainActivity.this, RandomIntentService.class);
    randomStart.setAction(Constants.ACTION_RANDOM_START);
    getApplicationContext().startService(randomStart);

    updateWordsList();
}

From source file:edu.mit.media.funf.configured.ConfiguredPipeline.java

@Override
protected void onHandleIntent(Intent intent) {
    String action = intent.getAction();
    if (ACTION_RELOAD.equals(action)) {
        reload();//from w  w  w.  j  av  a 2s .c  o m
    } else if (ACTION_UPDATE_CONFIG.equals(action)) {
        String config = intent.getStringExtra(CONFIG);
        String configUrl = intent.getStringExtra(CONFIG_URL);
        String configFilePath = intent.getStringExtra(CONFIG_FILE);
        if (config != null) {
            updateConfig(config);
        } else if (configFilePath != null) {
            File file = new File(configFilePath);
            updateConfig(file);
        } else if (configUrl != null) {
            try {
                updateConfig(new URL(configUrl));
            } catch (MalformedURLException e) {
                Log.e(TAG, "Unable to parse config url.");
            }
        } else {
            updateConfig();
        }
    } else if (ACTION_UPLOAD_DATA.equals(action)) {
        uploadData();
    } else if (ACTION_ARCHIVE_DATA.equals(action)) {
        archiveData();
    } else if (ACTION_ENABLE.equals(action)) {
        setEnabled(true);
    } else if (ACTION_DISABLE.equals(action)) {
        setEnabled(false);
    } else if (Probe.ACTION_DATA.equals(action)) {
        onDataReceived(intent.getExtras());
    } else if (Probe.ACTION_STATUS.equals(action)) {
        onStatusReceived(new Probe.Status(intent.getExtras()));
    } else if (Probe.ACTION_DETAILS.equals(action)) {
        onDetailsReceived(new Probe.Details(intent.getExtras()));
    }
}

From source file:ca.zadrox.dota2esportticker.service.UpdateTeamsService.java

@Override
protected void onHandleIntent(Intent intent) {
    final String action = intent.getAction();

    if (ACTION_UPDATE_TOP_TEAMS.equals(action)) {
        updateTopTeams();/*from w w  w .j  av  a 2s .c  om*/
    }

    final String searchName = intent.getStringExtra(EXTRA_SEARCH_NAME);

    if (searchName == null) {
        return;
    }

    if (ACTION_UPDATE_SEARCHED_TEAMS.equals(action)) {
        updateSearchedTeams(searchName);
    }
}

From source file:net.qvex.dommel.data.DommelDataService.java

/**
 * Does the actual work.//from w  w  w. j  av a  2  s  . c  o m
 */

@Override
protected void onHandleIntent(Intent intent) {
    String action = intent.getAction();

    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    final boolean manualUpdate = intent.getBooleanExtra(FIELD_MANUAL, false);

    // send broadcast containing error message
    Intent i = new Intent(MESSAGE_STATUS);
    i.putExtra(FIELD_MANUAL, manualUpdate);

    try {
        i.putExtra(FIELD_STATUS, STATUS_RUNNING);
        sendBroadcast(i);

        update();

        i.putExtra(FIELD_STATUS, STATUS_FINISHED);
        sendBroadcast(i);

    } catch (Exception e) {

    }

}

From source file:com.marlonjones.voidlauncher.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;//from   ww  w.  ja  v a  2 s. c  o  m
    }
    PendingInstallShortcutInfo info = createPendingInfo(context, data);
    if (info != null) {
        if (!info.isLauncherActivity()) {
            // Since its a custom shortcut, verify that it is safe to launch.
            if (!PackageManagerHelper.hasPermissionForActivity(context, info.launchIntent, null)) {
                // Target cannot be launched, or requires some special permission to launch
                Log.e(TAG, "Ignoring malicious intent " + info.launchIntent.toUri(0));
                return;
            }
        }
        queuePendingShortcutInfo(info, context);
    }
}

From source file:org.zywx.wbpalmstar.platform.push.PushRecieveMsgReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String packg = intent.getPackage();
    if (TextUtils.isEmpty(packg) || !packg.equals(context.getPackageName().toString())) {
        return;/*from  w  w w . j  av  a2  s  .co m*/
    }
    if (ACTION_PUSH.equals(intent.getAction())) {
        if (intent.hasExtra(PushReportConstants.PUSH_DATA_INFO_KEY)) {
            newPushNotification(context, intent);
        } else {
            oldPushNotification(context, intent);
        }
    }
}

From source file:com.physicaroid.pocketduino.cordova.PocketDuino.java

/**
 * USB???/*from  ww  w.j  a  v a 2 s  . c o m*/
 */
private void listenUsbDevice(CallbackContext callbackContext) {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    intentFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    this.usbCallbackContext = callbackContext;
    if (this.mUsbReceiver == null) {
        this.mUsbReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String handlerName = null;
                String action = intent.getAction();
                if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
                    // plugin result of USB attached
                    handlerName = HANDLER_PREFIX + "." + "attached";
                }
                if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
                    // plugin result of USB detached
                    handlerName = HANDLER_PREFIX + "." + "detached";
                }
                try {
                    String json = "{\"handlerName\":" + handlerName + " }";
                    JSONObject parameter = new JSONObject(json);
                    PluginResult dataResult = new PluginResult(PluginResult.Status.OK, parameter);
                    dataResult.setKeepCallback(true);
                    usbCallbackContext.sendPluginResult(dataResult);
                } catch (JSONException e) {
                    Log.e(POCKETDUINO, "Exception: " + e.getMessage());
                    usbCallbackContext.error(e.toString());
                }
            }
        };
        webView.getContext().registerReceiver(this.mUsbReceiver, intentFilter);
    }
}

From source file:com.nextgis.mobile.services.DataSendService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "Received start id " + startId + ": " + intent);
    super.onStartCommand(intent, flags, startId);
    if (intent == null)
        return START_STICKY;
    String action = intent.getAction();
    if (action.equals(DATASEND_ACTION_STOP)) {
        //Toast.makeText(getApplicationContext(), "Send position service stoped", Toast.LENGTH_SHORT).show();
        stopSelf();/*w w  w  .j  a  v  a2s .co m*/
    } else if (action.equals(DATASEND_ACTION_START)) {
        SharedPreferences prefs = getSharedPreferences(Constants.SERVICE_PREF, MODE_MULTI_PROCESS);
        boolean bStart = prefs.getBoolean(Constants.KEY_PREF_SW_SENDPOS_SRV, false);
        if (bStart)
            new SendPositionDataTask().execute(getApplicationContext());
        else
            //Toast.makeText(getApplicationContext(), "Send position service started", Toast.LENGTH_SHORT).show();
            stopSelf();
    }
    return START_STICKY;
}

From source file:cn.bingoogolapple.scaffolding.util.AppManager.java

private AppManager() {
    // ?//  w ww.j av a  2s. co  m
    CrashHandler.getInstance().init();

    sApp.registerReceiver(new BroadcastReceiver() {
        private boolean mIsFirstReceiveBroadcast = true;

        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                if (!mIsFirstReceiveBroadcast) {
                    try {
                        if (NetUtil.isNetworkAvailable()) {
                            RxBus.send(new RxEvent.NetworkConnectedEvent());
                        } else {
                            RxBus.send(new RxEvent.NetworkDisconnectedEvent());
                        }
                    } catch (Exception e) {
                    }
                } else {
                    mIsFirstReceiveBroadcast = false;
                }
            }
        }
    }, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}