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:br.com.maracujas.classicrockwallpapersfinal.MyDownloadService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand:" + intent + ":" + startId);

    if (ACTION_DOWNLOAD.equals(intent.getAction())) {
        // Get the path to download from the intent
        final String downloadPath = intent.getStringExtra(EXTRA_DOWNLOAD_PATH);

        // Mark task started
        Log.d(TAG, ACTION_DOWNLOAD + ":" + downloadPath);
        taskStarted();//from www  . ja v  a2 s.co  m
        Log.d(TAG, mStorage.child(downloadPath).toString());

        // Download and get total bytes
        mStorage.child(downloadPath).getStream()
                .addOnSuccessListener(new OnSuccessListener<StreamDownloadTask.TaskSnapshot>() {
                    @Override
                    public void onSuccess(StreamDownloadTask.TaskSnapshot taskSnapshot) {
                        Log.d(TAG, "download:SUCCESS");

                        // Send success broadcast with number of bytes downloaded
                        Intent broadcast = new Intent(ACTION_COMPLETED);
                        broadcast.putExtra(EXTRA_DOWNLOAD_PATH, downloadPath);
                        broadcast.putExtra(EXTRA_BYTES_DOWNLOADED, taskSnapshot.getTotalByteCount());
                        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(broadcast);

                        // Mark task completed
                        taskCompleted();
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                        Log.w(TAG, "download:FAILURE", exception);

                        // Send failure broadcast
                        Intent broadcast = new Intent(ACTION_ERROR);
                        broadcast.putExtra(EXTRA_DOWNLOAD_PATH, downloadPath);
                        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(broadcast);

                        // Mark task completed
                        taskCompleted();
                    }
                });
    }

    return START_REDELIVER_INTENT;
}

From source file:org.thinkfree.axihome.NFC.TagViewer.java

void resolveIntent(Intent intent) {

    Log.e(TAG, "Tag detected");
    String action = intent.getAction();

    Log.e(TAG, action);//ww  w  .  j a va 2s .  co  m

    if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {

        Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
        NdefMessage[] msgs;

        if (rawMsgs != null) {
            msgs = new NdefMessage[rawMsgs.length];
            for (int i = 0; i < rawMsgs.length; i++) {
                msgs[i] = (NdefMessage) rawMsgs[i];
            }
        } else {
            // Unknown tag type
            Log.e(TAG, "Unknown tag type");
            byte[] empty = new byte[] {};
            NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty);
            NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
            msgs = new NdefMessage[] { msg };
        }
        // Setup the views
        processMessage(msgs);
    } else {

        Log.e(TAG, "Unknown intent " + intent);
        finish();
        return;
    }
}

From source file:com.dattasmoon.pebble.plugin.FireReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    if (com.twofortyfouram.locale.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) {
        // fetch this for later, we may need it in case we change things
        // around and we need to know what version of the code they were
        // running when they saved the action
        int bundleVersionCode = intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_VERSION_CODE, 1);

        Type type = Type.values()[intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_TYPE,
                Type.NOTIFICATION.ordinal())];
        PowerManager pm;/*from   ww w.ja  v  a 2  s  . c o  m*/
        switch (type) {
        case NOTIFICATION:
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);

            // handle screen DND
            boolean notifScreenOn = sharedPref.getBoolean(Constants.PREFERENCE_NOTIF_SCREEN_ON, true);
            pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            if (Constants.IS_LOGGABLE) {
                Log.d(Constants.LOG_TAG, "FireReceiver.onReceive: notifScreenOn=" + notifScreenOn + "  screen="
                        + pm.isScreenOn());
            }
            if (!notifScreenOn && pm.isScreenOn()) {
                break;
            }

            //handle quiet hours DND
            boolean quiet_hours = sharedPref.getBoolean(Constants.PREFERENCE_QUIET_HOURS, false);
            //we only need to pull this if quiet hours are enabled. Save the cycles for the cpu! (haha)
            if (quiet_hours) {
                String[] pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_BEFORE, "00:00")
                        .split(":");
                Date quiet_hours_before = new Date(0, 0, 0, Integer.parseInt(pieces[0]),
                        Integer.parseInt(pieces[1]));
                pieces = sharedPref.getString(Constants.PREFERENCE_QUIET_HOURS_AFTER, "23:59").split(":");
                Date quiet_hours_after = new Date(0, 0, 0, Integer.parseInt(pieces[0]),
                        Integer.parseInt(pieces[1]));
                Calendar c = Calendar.getInstance();
                Date now = new Date(0, 0, 0, c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE));
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "Checking quiet hours. Now: " + now.toString() + " vs "
                            + quiet_hours_before.toString() + " and " + quiet_hours_after.toString());
                }
                if (now.before(quiet_hours_before) || now.after(quiet_hours_after)) {
                    if (Constants.IS_LOGGABLE) {
                        Log.i(Constants.LOG_TAG, "Time is before or after the quiet hours time. Returning.");
                    }
                    break;
                }
            }

            String title = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_TITLE);
            String body = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_BODY);

            sendAlertToPebble(context, bundleVersionCode, title, body);
            break;
        case SETTINGS:
            Mode mode = Mode.values()[intent.getIntExtra(Constants.BUNDLE_EXTRA_INT_MODE, Mode.OFF.ordinal())];
            String packageList = intent.getStringExtra(Constants.BUNDLE_EXTRA_STRING_PACKAGE_LIST);

            setNotificationSettings(context, bundleVersionCode, mode, packageList);
            break;
        }
    }
}

From source file:ee.ria.DigiDoc.activity.OpenExternalFileActivity.java

private void handleIntentAction() {
    Intent intent = getIntent();
    ContainerFacade container = null;//from  w ww .  j  a  v  a2s. c  o m
    Timber.d("Handling action: %s ", intent.getAction());
    switch (intent.getAction()) {
    case Intent.ACTION_VIEW:
        try {
            container = createContainer(intent.getData());
        } catch (Exception e) {
            Timber.e(e, "Error creating container from uri %s", intent.getData().toString());
        }
        break;
    case Intent.ACTION_SEND:
        Uri sendUri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
        if (sendUri != null) {
            container = createContainer(sendUri);
        }
        break;
    case Intent.ACTION_SEND_MULTIPLE:
        ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
        if (uris != null) {
            container = createContainer(uris);
        }
        break;
    }

    if (container != null) {
        createContainerDetailsFragment(container);
    } else {
        createErrorFragment();
    }
}

From source file:com.sonetel.plugins.sonetelcallthru.CallThru.java

@Override
public void onReceive(final Context context, Intent intent) {
    if (SipManager.ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {
        // Retrieve and cache infos from the phone app 
        if (!sPhoneAppInfoLoaded) {
            Resources r = context.getResources();
            BitmapDrawable drawable = (BitmapDrawable) r.getDrawable(R.drawable.ic_wizard_sonetel);
            sPhoneAppBmp = drawable.getBitmap();

            sPhoneAppInfoLoaded = true;//from w  ww  .ja  v  a2  s.  com
        }

        Bundle results = getResultExtras(true);
        //if(pendingIntent != null) {
        //   results.putParcelable(CallHandlerPlugin.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        //}
        results.putString(Intent.EXTRA_TITLE, "Call thru");// context.getResources().getString(R.string.use_pstn));
        if (sPhoneAppBmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, sPhoneAppBmp);
        }
        if (intent.getStringExtra(Intent.EXTRA_TEXT) == null)
            return;

        //final PendingIntent pendingIntent = null;
        final String callthrunum = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        final String dialledNum = intent.getStringExtra(Intent.EXTRA_TEXT);
        // We must handle that clean way cause when call just to 
        // get the row in account list expect this to reply correctly
        if (callthrunum != null && PhoneCapabilityTester.isPhone(context)) {

            if (!callthrunum.equalsIgnoreCase("")) {
                DBAdapter dbAdapt = new DBAdapter(context);

                // Build pending intent

                SipAccount = dbAdapt.getAccount(1);

                if (SipAccount != null) {

                    Intent i = new Intent(Intent.ACTION_CALL);
                    i.setData(Uri.fromParts("tel", callthrunum, null));
                    final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i,
                            PendingIntent.FLAG_CANCEL_CURRENT);

                    NetWorkThread = new Thread() {
                        public void run() {
                            SendMsgToNetWork(dialledNum, context, pendingIntent);
                        };
                    };

                    NetWorkThread.start();

                }

                if (!dialledNum.equalsIgnoreCase("")) {
                    SipCallSessionImpl callInfo = new SipCallSessionImpl();

                    callInfo.setRemoteContact(dialledNum);
                    callInfo.setIncoming(false);
                    callInfo.callStart = System.currentTimeMillis();
                    callInfo.setAccId(3);
                    //callInfo.setLastStatusCode(pjsua.PJ_SUCCESS);

                    ContentValues cv = CallLogHelper.logValuesForCall(context, callInfo, callInfo.callStart);
                    context.getContentResolver().insert(SipManager.CALLLOG_URI, cv);

                }
            } else {
                Location_Finder LocFinder = new Location_Finder(context);
                if (LocFinder.getContryName().startsWith("your"))
                    Toast.makeText(context,
                            "Country of your current location unknown. Call thru not available.",
                            Toast.LENGTH_LONG).show();
                else
                    Toast.makeText(context,
                            "No Call thru access number available in " + LocFinder.getContryName(),
                            Toast.LENGTH_LONG).show();
                //Toast.makeText(context, "No Call thru access number available in ", Toast.LENGTH_LONG).show();
            }
        }

        // This will exclude next time tel:xxx is raised from csipsimple treatment which is wanted
        results.putString(Intent.EXTRA_PHONE_NUMBER, callthrunum);

    }

}

From source file:com.csipsimple.plugins.twvoip.CallHandler.java

@Override
public void onReceive(Context context, Intent intent) {
    if (ACTION_GET_PHONE_HANDLERS.equals(intent.getAction())) {

        PendingIntent pendingIntent = null;
        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_12VOIP_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_12VOIP_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_12VOIP_NBR, "");

        // We must handle that clean way cause when call just to
        // get the row in account list expect this to reply correctly
        if (!TextUtils.isEmpty(number) && !TextUtils.isEmpty(user) && !TextUtils.isEmpty(nbr)
                && !TextUtils.isEmpty(pwd)) {
            // Build pending intent
            Intent i = new Intent(ACTION_DO_TWVOIP_CALL);
            i.setClass(context, getClass());
            i.putExtra(Intent.EXTRA_PHONE_NUMBER, number);

            pendingIntent = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
            // = PendingIntent.getActivity(context, 0, i, 0);
        }//from  w  w w.j ava  2  s.  co m

        // Build icon
        Bitmap bmp = null;
        Drawable icon = context.getResources().getDrawable(R.drawable.icon);
        BitmapDrawable bd = ((BitmapDrawable) icon);
        bmp = bd.getBitmap();

        // Build the result for the row (label, icon, pending intent, and
        // excluded phone number)
        Bundle results = getResultExtras(true);
        if (pendingIntent != null) {
            results.putParcelable(Intent.EXTRA_REMOTE_INTENT_TOKEN, pendingIntent);
        }
        results.putString(Intent.EXTRA_TITLE, "12voip WebCallback");
        if (bmp != null) {
            results.putParcelable(Intent.EXTRA_SHORTCUT_ICON, bmp);
        }

        // DO *NOT* exclude from next tel: intent cause we use a http method
        // results.putString(Intent.EXTRA_PHONE_NUMBER, number);

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

        // Extract infos from intent received
        String number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        // Extract infos from settings
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String user = prefs.getString(CallHandlerConfig.KEY_12VOIP_USER, "");
        String pwd = prefs.getString(CallHandlerConfig.KEY_12VOIP_PWD, "");
        String nbr = prefs.getString(CallHandlerConfig.KEY_12VOIP_NBR, "");

        // params
        List<NameValuePair> params = new LinkedList<NameValuePair>();
        params.add(new BasicNameValuePair("username", user));
        params.add(new BasicNameValuePair("password", pwd));
        params.add(new BasicNameValuePair("from", nbr));
        params.add(new BasicNameValuePair("to", number));
        String paramString = URLEncodedUtils.format(params, "utf-8");

        String requestURL = "https://www.12voip.com//myaccount/makecall.php?" + paramString;

        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(requestURL);

        // Create a response handler
        HttpResponse httpResponse;
        try {
            httpResponse = httpClient.execute(httpGet);
            Log.d(THIS_FILE, "response code is " + httpResponse.getStatusLine().getStatusCode());
            if (httpResponse.getStatusLine().getStatusCode() == 200) {
                InputStreamReader isr = new InputStreamReader(httpResponse.getEntity().getContent());
                BufferedReader br = new BufferedReader(isr);

                String line;
                String fullReply = "";
                boolean foundSuccess = false;
                while ((line = br.readLine()) != null) {
                    if (!TextUtils.isEmpty(line) && line.toLowerCase().contains("success")) {
                        showToaster(context, "Success... wait a while you'll called back");
                        foundSuccess = true;
                        break;
                    }
                    if (!TextUtils.isEmpty(line)) {
                        fullReply = fullReply.concat(line);
                    }
                }
                if (!foundSuccess) {
                    showToaster(context, "Error : server error : " + fullReply);
                }
            } else {
                showToaster(context, "Error : invalid request " + httpResponse.getStatusLine().getStatusCode());
            }
        } catch (ClientProtocolException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        } catch (IOException e) {
            showToaster(context, "Error : " + e.getLocalizedMessage());
        }

    }
}

From source file:org.jnegre.android.osmonthego.service.ExportService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        if (ACTION_EXPORT_OSM.equals(action)) {
            boolean includeAddress = intent.getBooleanExtra(EXTRA_INCLUDE_ADDRESS, false);
            boolean includeFixme = intent.getBooleanExtra(EXTRA_INCLUDE_FIXME, false);
            handleOsmExport(includeAddress, includeFixme);
        }//from w  w  w.j  a v a2 s .  com
    }
}

From source file:com.google.android.apps.muzei.featuredart.FeaturedArtSource.java

@Override
protected void onHandleIntent(Intent intent) {
    if (BuildConfig.DEBUG && intent != null && "demoartwork".equals(intent.getAction())) {
        publishArtwork(new Artwork.Builder().imageUri(Uri.parse(intent.getStringExtra("image")))
                .title(intent.getStringExtra("title")).token(intent.getStringExtra("image"))
                .byline(intent.getStringExtra("byline"))
                .viewIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(intent.getStringExtra("details"))))
                .build());/* w  w  w  .j  av a 2  s. c o m*/
        removeAllUserCommands();
    }

    super.onHandleIntent(intent);
}

From source file:com.mobilesolutionworks.android.httpcache.WorksHttpCacheService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        String action = intent.getAction();
        if (mConfiguration.action.equals(action)) {
            refreshData(intent);//from  w ww .  j  av  a  2s.  c om
        }
    }
}

From source file:com.BeeFramework.service.PushMessageReceiver.java

/**
 *
 *
 * @param context/*from  w w  w. j  a  va  2  s . c  om*/
 *            Context
 * @param intent
 *            intent
 */
@Override
public void onReceive(final Context context, Intent intent) {
    shared = context.getSharedPreferences("userInfo", 0);
    editor = shared.edit();

    if (intent.getAction().equals(PushConstants.ACTION_MESSAGE)) {
        //??
        //            String message = intent.getExtras().getString(
        //                    PushConstants.EXTRA_PUSH_MESSAGE_STRING);
        //
        //            //??CUSTOM_KEY????key
        //            String customContentString = intent.getExtras().getString("content");
        //
        //            //??,?demo?
        //            Intent responseIntent = null;
        //            responseIntent = new Intent(SquaredActivity.ACTION_MESSAGE);
        //            responseIntent.putExtra(SquaredActivity.EXTRA_MESSAGE, message);
        //            responseIntent.setClass(context, SquaredActivity.class);
        //            responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //            context.startActivity(responseIntent);

        //??
        //:PushManager.startWork()PushConstants.METHOD_BIND
    } else if (intent.getAction().equals(PushConstants.ACTION_RECEIVE)) {
        //?
        final String method = intent.getStringExtra(PushConstants.EXTRA_METHOD);
        //?,???bind??bind,??startWork
        final int errorCode = intent.getIntExtra(PushConstants.EXTRA_ERROR_CODE, PushConstants.ERROR_SUCCESS);
        //
        final String content = new String(intent.getByteArrayExtra(PushConstants.EXTRA_CONTENT));

        //??,?demo?

        //            Intent responseIntent = null;
        //            responseIntent = new Intent(SquaredActivity.ACTION_RESPONSE);
        //            responseIntent.putExtra(SquaredActivity.RESPONSE_METHOD, method);
        //            responseIntent.putExtra(SquaredActivity.RESPONSE_ERRCODE,
        //                    errorCode);
        //            responseIntent.putExtra(SquaredActivity.RESPONSE_CONTENT, content);
        //            responseIntent.setClass(context, SquaredActivity.class);
        //            responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //            context.startActivity(responseIntent);

        if (errorCode == 0) {
            String appid = "";
            String channelid = "";
            String userid = "";
            try {
                JSONObject jsonContent = new JSONObject(content);
                JSONObject params = jsonContent.getJSONObject("response_params");
                appid = params.getString("appid");
                channelid = params.getString("channel_id");
                userid = params.getString("user_id");
                editor.putString("UUID", userid);
                editor.commit();
            } catch (JSONException e) {

            }

        }

        //??
    } else if (intent.getAction().equals(PushConstants.ACTION_RECEIVER_NOTIFICATION_CLICK)) {

        //            String content = intent
        //                    .getStringExtra(PushConstants.EXTRA_NOTIFICATION_CONTENT);
        //
        //            Intent responseIntent = null;
        //            responseIntent = new Intent(SquaredActivity.ACTION_PUSHCLICK);
        //
        //
        //            responseIntent.setClass(context, SquaredActivity.class);
        //            responseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //
        //            //??CUSTOM_KEY????key
        //            String customContentString = intent.getExtras().getString("content");
        //            responseIntent.putExtra(SquaredActivity.CUSTOM_CONTENT, customContentString);
        //
        //            context.startActivity(responseIntent);
    }
}