Example usage for android.content Intent hasExtra

List of usage examples for android.content Intent hasExtra

Introduction

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

Prototype

public boolean hasExtra(String name) 

Source Link

Document

Returns true if an extra value is associated with the given name.

Usage

From source file:com.bullmobi.base.ui.activities.SettingsActivity.java

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);

    // Should happen before any call to getIntent()
    getMetaData();//from  www. j a va 2  s . co  m

    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
        getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
    }

    // Getting Intent properties can only be done after the super.onCreate(...)
    final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);

    mIsShortcut = isShortCutIntent(intent) || isLikeShortCutIntent(intent)
            || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, false);

    final ComponentName cn = intent.getComponent();
    final String className = cn.getClassName();

    boolean isShowingDashboard = className.equals(Settings2.class.getName());

    // This is a "Sub Settings" when:
    // - this is a real SubSettings
    // - or :settings:show_fragment_as_subsetting is passed to the Intent
    final boolean isSubSettings = className.equals(SubSettings.class.getName())
            || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);

    // If this is a sub settings, then apply the SubSettings Theme for the ActionBar content insets
    if (isSubSettings) {
        // Check also that we are not a Theme Dialog as we don't want to override them
        /*
        final int themeResId = getTheme(). getThemeResId();
        if (themeResId != R.style.Theme_DialogWhenLarge &&
            themeResId != R.style.Theme_SubSettingsDialogWhenLarge) {
        setTheme(R.style.Theme_SubSettings);
        }
        */
    }

    setContentView(R.layout.settings_main_dashboard);

    mContent = (ViewGroup) findViewById(R.id.main_content);

    getSupportFragmentManager().addOnBackStackChangedListener(this);

    if (savedState != null) {
        // We are restarting from a previous saved state; used that to initialize, instead
        // of starting fresh.

        setTitleFromIntent(intent);

        ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
        if (categories != null) {
            mCategories.clear();
            mCategories.addAll(categories);
            setTitleFromBackStack();
        }

        mDisplayHomeAsUpEnabled = savedState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
    } else {
        if (!isShowingDashboard) {
            mDisplayHomeAsUpEnabled = isSubSettings;
            setTitleFromIntent(intent);

            Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
            switchToFragment(initialFragmentName, initialArguments, true, false, mInitialTitleResId,
                    mInitialTitle, false);
        } else {
            mDisplayHomeAsUpEnabled = false;
            mInitialTitleResId = R.string.app_name;
            switchToFragment(DashboardFragment.class.getName(), null, false, false, mInitialTitleResId,
                    mInitialTitle, false);
        }
    }

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(mDisplayHomeAsUpEnabled);
        actionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
    }
}

From source file:com.ffmpegtest.VideoActivity.java

private void setDataSource() {
    HashMap<String, String> params = new HashMap<String, String>();

    // set font for ass
    File assFont = new File(Environment.getExternalStorageDirectory(), "DroidSansFallback.ttf");
    params.put("ass_default_font_path", assFont.getAbsolutePath());

    Intent intent = getIntent();
    String url = intent.getStringExtra(AppConstants.VIDEO_PLAY_ACTION_EXTRA_URL);
    if (url == null) {
        throw new IllegalArgumentException(
                String.format("\"%s\" did not provided", AppConstants.VIDEO_PLAY_ACTION_EXTRA_URL));
    }/* w  w  w.ja  v a 2 s  .  c  om*/
    if (intent.hasExtra(AppConstants.VIDEO_PLAY_ACTION_EXTRA_ENCRYPTION_KEY)) {
        params.put("aeskey", intent.getStringExtra(AppConstants.VIDEO_PLAY_ACTION_EXTRA_ENCRYPTION_KEY));
    }

    this.mPlayPauseButton.setBackgroundResource(android.R.drawable.ic_media_play);
    this.mPlayPauseButton.setEnabled(true);
    mPlay = false;

    mMpegPlayer.setDataSource(url, params, FFmpegPlayer.UNKNOWN_STREAM, mAudioStreamNo, mSubtitleStreamNo);

}

From source file:com.owncloud.android.files.services.FileDownloader.java

/**
 * Entry point to add one or several files to the queue of downloads.
 *
 * New downloads are added calling to startService(), resulting in a call to this method.
 * This ensures the service will keep on working although the caller activity goes away.
 *//*from  w w  w.  ja va 2s . c  o  m*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);

    if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return START_NOT_STICKY;
    } else {
        final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
        final OCFile file = intent.getParcelableExtra(EXTRA_FILE);
        AbstractList<String> requestedDownloads = new Vector<String>();
        try {
            DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
            newDownload.addDatatransferProgressListener(this);
            newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
            Pair<String, String> putResult = mPendingDownloads.putIfAbsent(account, file.getRemotePath(),
                    newDownload);
            String downloadKey = putResult.first;
            requestedDownloads.add(downloadKey);

            sendBroadcastNewDownload(newDownload, putResult.second);

        } catch (IllegalArgumentException e) {
            Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
            return START_NOT_STICKY;
        }

        if (requestedDownloads.size() > 0) {
            Message msg = mServiceHandler.obtainMessage();
            msg.arg1 = startId;
            msg.obj = requestedDownloads;
            mServiceHandler.sendMessage(msg);
        }
        //}
    }

    return START_NOT_STICKY;
}

From source file:com.cerema.cloud2.files.services.FileDownloader.java

/**
 * Entry point to add one or several files to the queue of downloads.
 *
 * New downloads are added calling to startService(), resulting in a call to this method.
 * This ensures the service will keep on working although the caller activity goes away.
 *///from   w w w .  jav  a 2  s . co  m
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);

    if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return START_NOT_STICKY;
    } else {
        final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
        final OCFile file = intent.getParcelableExtra(EXTRA_FILE);
        AbstractList<String> requestedDownloads = new Vector<String>();
        try {
            DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
            newDownload.addDatatransferProgressListener(this);
            newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
            Pair<String, String> putResult = mPendingDownloads.putIfAbsent(account, file.getRemotePath(),
                    newDownload);
            if (putResult != null) {
                String downloadKey = putResult.first;
                requestedDownloads.add(downloadKey);
                sendBroadcastNewDownload(newDownload, putResult.second);
            } // else, file already in the queue of downloads; don't repeat the request

        } catch (IllegalArgumentException e) {
            Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
            return START_NOT_STICKY;
        }

        if (requestedDownloads.size() > 0) {
            Message msg = mServiceHandler.obtainMessage();
            msg.arg1 = startId;
            msg.obj = requestedDownloads;
            mServiceHandler.sendMessage(msg);
        }
        //}
    }

    return START_NOT_STICKY;
}

From source file:edu.cmu.plugins.PhoneListener.java

/**
 * Sets the context of the Command. This can then be used to do things like
 * get file paths associated with the Activity.
 * /*from w  w  w  .j a v a  2 s.  c  om*/
 * @param ctx The context of the main Activity.
 */
public void setContext(PhonegapActivity ctx) {
    super.setContext(ctx);
    this.phoneListenerCallbackId = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
    intentFilter.addAction("android.provider.Telephony.SMS_RECEIVED");

    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {

            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent == null) {
                    return;
                }
                String state = "";
                if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
                    state = "SMS_RECEIVED";
                    Log.i(LOG_TAG, state);
                }
                if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    // State has changed
                    String phoneState = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : null;

                    // See if the new state is 'ringing', 'off hook' or 'idle'
                    if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        // phone is ringing, awaiting either answering or canceling
                        state = "RINGING";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                        // actually talking on the phone... either making a call or having answered one
                        state = "OFFHOOK";
                        Log.i(LOG_TAG, state);
                    } else if (phoneState != null && phoneState.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                        // idle means back to no calls in or out. default state.
                        state = "IDLE";
                        Log.i(LOG_TAG, state);
                    } else {
                        state = TYPE_NONE;
                        Log.i(LOG_TAG, state);
                    }
                }
                updatePhoneState(state, true);
            }
        };
        // register the receiver... this is so it doesn't have to be added to AndroidManifest.xml
        ctx.registerReceiver(this.receiver, intentFilter);
    }
}

From source file:com.chao.facebookzc.widget.FacebookDialog.java

static private String getEventName(Intent intent) {
    String action = intent.getStringExtra(NativeProtocol.EXTRA_PROTOCOL_ACTION);
    boolean hasPhotos = intent.hasExtra(NativeProtocol.EXTRA_PHOTOS);
    return getEventName(action, hasPhotos);
}

From source file:com.locosoft.imageselector.MultiImageSelectorActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mFakeR = new FakeR(this);
    setContentView(mFakeR.getId("layout", "activity_image_selector"));

    Intent intent = getIntent();
    mDefaultCount = intent.getIntExtra(EXTRA_SELECT_COUNT, 9);
    int mode = intent.getIntExtra(EXTRA_SELECT_MODE, MODE_MULTI);
    boolean isShow = intent.getBooleanExtra(EXTRA_SHOW_CAMERA, true);
    if (mode == MODE_MULTI && intent.hasExtra(EXTRA_DEFAULT_SELECTED_LIST)) {
        resultList = intent.getStringArrayListExtra(EXTRA_DEFAULT_SELECTED_LIST);
    }/*w  w  w  .  j a  v a 2s.  co  m*/

    desiredWidth = intent.getIntExtra(EXTRA_WIDTH, 0);
    desiredHeight = intent.getIntExtra(EXTRA_HEIGHT, 0);
    quality = intent.getIntExtra(EXTRA_QUALITY, 0);
    fixRotation = intent.getBooleanExtra(EXTRA_FIXROTATION, false);

    Bundle bundle = new Bundle();
    bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_COUNT, mDefaultCount);
    bundle.putInt(MultiImageSelectorFragment.EXTRA_SELECT_MODE, mode);
    bundle.putBoolean(MultiImageSelectorFragment.EXTRA_SHOW_CAMERA, isShow);
    bundle.putStringArrayList(MultiImageSelectorFragment.EXTRA_DEFAULT_SELECTED_LIST, resultList);

    getSupportFragmentManager().beginTransaction().add(mFakeR.getId("id", "imageselector_image_grid"),
            Fragment.instantiate(this, MultiImageSelectorFragment.class.getName(), bundle)).commit();

    // back button
    findViewById(mFakeR.getId("id", "imageselector_btn_back")).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setResult(RESULT_CANCELED);
            finish();
        }
    });

    // done button
    mSubmitButton = (Button) findViewById(mFakeR.getId("id", "imageselector_commit"));
    if (resultList == null || resultList.size() <= 0) {
        mSubmitButton.setText(mFakeR.getId("string", "imageselector_done"));
        mSubmitButton.setEnabled(false);
    } else {
        mSubmitButton.setText(getResources().getString(mFakeR.getId("string", "imageselector_done")) + "("
                + resultList.size() + "/" + mDefaultCount + ")");

        mSubmitButton.setEnabled(true);
    }
    mSubmitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (resultList != null && resultList.size() > 0) {
                // return the selection array list
                if (desiredHeight == 0 && desiredWidth == 0 && quality == 100 && !fixRotation) {
                    Intent data = new Intent();
                    data.putStringArrayListExtra(EXTRA_RESULT, resultList);
                    setResult(RESULT_OK, data);
                    finish();
                } else {
                    postProcessImages();
                }
            }
        }
    });

    progress = new ProgressDialog(this);
    progress.setTitle(getResources().getString(mFakeR.getId("string", "imageselector_progress_title")));
    progress.setMessage(getResources().getString(mFakeR.getId("string", "imageselector_progress_content")));
}

From source file:com.otaupdater.DownloadReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action == null)
        return;// w w w.  jav  a2 s . com

    if (action.equals(DL_ROM_ACTION)) {
        RomInfo.FACTORY.clearUpdateNotif(context);
        RomInfo.FACTORY.fromIntent(intent).startDownload(context);
    } else if (action.equals(DL_KERNEL_ACTION)) {
        KernelInfo.FACTORY.clearUpdateNotif(context);
        KernelInfo.FACTORY.fromIntent(intent).startDownload(context);
    } else if (action.equals(CLEAR_DL_ACTION)) {
        if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) {
            DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
            dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
            DownloadBarFragment.notifyActiveFragment();
        }
    } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) {
        DownloadStatus status = DownloadStatus.forDownloadID(context,
                intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1));
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile()
                : status.getReason();

        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        if (error == 0) {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent flashIntent = new Intent(context, DownloadsActivity.class);
            flashIntent.setAction(info.getFlashAction());
            info.addToIntent(flashIntent);
            PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadDoneTitle()))
                    .setContentTitle(context.getString(info.getDownloadDoneTitle()))
                    .setSmallIcon(R.drawable.ic_stat_av_download)
                    .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent)
                    .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install),
                            flashPIntent)
                    .build();
            nm.notify(info.getFlashNotifID(), notif);
        } else {
            Intent mainIntent = new Intent(context, OTAUpdaterActivity.class);
            mainIntent.setAction(info.getNotifAction());
            info.addToIntent(mainIntent);
            PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent dlIntent = new Intent(context, DownloadReceiver.class);
            dlIntent.setAction(info.getDownloadAction());
            info.addToIntent(dlIntent);
            PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Intent clearIntent = new Intent(context, DownloadReceiver.class);
            clearIntent.setAction(CLEAR_DL_ACTION);
            clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId());
            PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

            Notification notif = new NotificationCompat.Builder(context)
                    .setTicker(context.getString(info.getDownloadFailedTitle()))
                    .setContentTitle(context.getString(info.getDownloadFailedTitle()))
                    .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning)
                    .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent)
                    .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent)
                    .build();
            nm.notify(info.getFailedNotifID(), notif);
        }
    } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) {
        long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS);
        if (ids.length == 0)
            return;

        DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]);
        if (status == null)
            return;

        BaseInfo info = status.getInfo();
        if (info == null)
            return;

        Intent i = new Intent(context, OTAUpdaterActivity.class);
        i.setAction(info.getNotifAction());
        i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

From source file:com.stasbar.knowyourself.timer.TimerFragment.java

@Override
public void onResume() {
    super.onResume();

    // We may have received a new intent while paused.
    final Intent intent = getActivity().getIntent();
    if (intent != null && intent.hasExtra(TimerService.EXTRA_TIMER_ID)) {
        // This extra is single-use; remove after honoring it.
        final int showTimerId = intent.getIntExtra(TimerService.EXTRA_TIMER_ID, -1);
        intent.removeExtra(TimerService.EXTRA_TIMER_ID);

        final Timer timer = DataModel.getDataModel().getTimer(showTimerId);
        if (timer != null) {
            // A specific timer must be shown; show the list of timers.
            final int index = DataModel.getDataModel().getTimers().indexOf(timer);
            mViewPager.setCurrentItem(index);

            animateToView(mTimersView, null);
        }//from   www. j  a v a2  s  .co m
    }
}

From source file:com.google.android.apps.dashclock.DashClockService.java

/**
 * Updates a widget's UI.//from  www. j a v  a2 s .  c om
 */
private void handleUpdateWidgets(Intent intent) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);

    // Either update all app widgets, or only those which were requested.
    int appWidgetIds[];
    if (intent.hasExtra(EXTRA_APPWIDGET_ID)) {
        appWidgetIds = new int[] { intent.getIntExtra(EXTRA_APPWIDGET_ID, -1) };
    } else {
        appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, WidgetProvider.class));
    }

    StringBuilder sb = new StringBuilder();
    for (int appWidgetId : appWidgetIds) {
        sb.append(appWidgetId).append(" ");
    }
    LOGD(TAG, "Rendering widgets with appWidgetId(s): " + sb);

    WidgetRenderer.renderWidgets(this, appWidgetIds);
}