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.btmura.android.reddit.app.BrowserActivity.java

@Override
protected boolean skipSetup(Bundle savedInstanceState) {
    Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_SUBREDDIT)) {
        requestedSubreddit = Strings.emptyToNull(intent.getStringExtra(EXTRA_SUBREDDIT));
    } else if (intent.getData() != null) {
        Uri data = intent.getData();/*from   ww  w  . j  a v  a 2  s .  c  o  m*/
        requestedSubreddit = Strings.emptyToNull(UriHelper.getSubreddit(data));
        requestedThingBundle = UriHelper.getThingBundle(data);
    }

    hasLeftFragment = !isSinglePane && drawerLayout == null && requestedSubreddit == null;
    showDrawer = drawerLayout != null && requestedSubreddit == null;

    if (isSinglePane && requestedSubreddit != null && requestedThingBundle != null) {
        selectThingSinglePane(null, requestedThingBundle);
        finish();
        return true;
    }
    return false;
}

From source file:com.gbozza.android.stockhawk.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent inboundIntent = getIntent();
    String symbol = null;//from   w w  w.j a v a2 s  .  c o m
    // intent coming from the app
    if (null != inboundIntent && inboundIntent.hasExtra(EXTRA_SYMBOL)) {
        symbol = inboundIntent.getStringExtra(EXTRA_SYMBOL);
    }
    // intent coming from the list widget
    if (null != inboundIntent && inboundIntent.hasExtra(ListWidgetService.EXTRA_LIST_WIDGET_SYMBOL)
            && null == savedInstanceState) {
        symbol = inboundIntent.getStringExtra(ListWidgetService.EXTRA_LIST_WIDGET_SYMBOL);
    }
    if (null != findViewById(R.id.stock_detail_container)) {
        mTwoPane = true;
        if (savedInstanceState == null) {
            if (null == symbol) {
                symbol = PrefUtils.getSymbolAtPos(this, 0);
            }
            DetailFragment fragment = new DetailFragment();
            Bundle args = new Bundle();
            args.putString(EXTRA_SYMBOL, symbol);
            fragment.setArguments(args);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.stock_detail_container, fragment, DETAILFRAGMENT_TAG).commit();
        }
    } else {
        if (null != symbol) {
            Intent intent = new Intent(this, DetailActivity.class).putExtra(EXTRA_SYMBOL, symbol);
            ActivityCompat.startActivity(this, intent, null);
        }
        mTwoPane = false;
    }

    mStockFragment = ((StockFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_stocks));
    mStockFragment.setTwoPane(mTwoPane);
}

From source file:com.example.android.appnavigation.app.ContentViewActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_view);

    ActionBarCompat.setDisplayHomeAsUpEnabled(this, true);

    Intent intent = getIntent();
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
        TextView tv = (TextView) findViewById(R.id.status_text);
        tv.setText("Viewing content from ACTION_VIEW");
    } else if (intent.hasExtra(EXTRA_TEXT)) {
        TextView tv = (TextView) findViewById(R.id.status_text);
        tv.setText(intent.getStringExtra(EXTRA_TEXT));
    }//from ww  w.j av a  2s.c o  m
}

From source file:com.linroid.pushapp.ui.send.SendActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_PACKAGE)) {
        this.pack = intent.getParcelableExtra(EXTRA_PACKAGE);
    } else if (intent.hasExtra(EXTRA_APPLICATION_INFO)) {
        this.appInfo = intent.getParcelableExtra(EXTRA_APPLICATION_INFO);
    } else {//from  ww  w.  j a va2 s .  c  om
        throw new IllegalArgumentException("EXTRA_PACKAGE or EXTRA_APPLICATION_INFO extra data required");
    }
    dialog = new ProgressDialog(this);
    dialog.setMessage(getString(R.string.msg_upload_prepare));
    dialog.setMax(100);
    dialog.setCancelable(false);
    dialog.setIndeterminate(true);
    getSupportFragmentManager().beginTransaction().replace(R.id.container, new DeviceFragment()).commit();

    App.from(this).component().inject(this);
}

From source file:com.adkdevelopment.e_contact.DetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.detail_fragment_task, container, false);
    mUnbinder = ButterKnife.bind(this, rootView);

    // to prevent multiple calls to getContext()
    Context context = getContext();

    Intent intent = getActivity().getIntent();
    TaskItem newsItem;/* w  w w. j a v a2s.c om*/

    if (intent.hasExtra(TaskItem.TASKITEM)) {

        newsItem = intent.getParcelableExtra(TaskItem.TASKITEM);

        // Time parsing and creating a nice textual version (should be changed to Calendar)
        String dateCreated = Utilities.getFormattedDate(newsItem.getCreated());
        String dateRegistered = Utilities.getFormattedDate(newsItem.getRegistered());
        String dateAssigned = Utilities.getFormattedDate(newsItem.getAssigned());

        mTaskTitleText.setText(Utilities.getType(context, newsItem.getType()));
        mTaskStatus.setText(Utilities.getStatus(context, newsItem.getStatus()));

        // sets color of a status TextView shape according to the schema
        GradientDrawable gradientDrawable = (GradientDrawable) mTaskStatus.getBackground();
        gradientDrawable.setColor(Utilities.getBackgroundColor(context, newsItem.getStatus()));

        mTaskCreatedDate.setText(dateCreated);
        mTaskRegisteredDate.setText(dateRegistered);
        mTaskAssignedDate.setText(dateAssigned);
        mTaskResponsibleName.setText(newsItem.getResponsible());
        mTaskDescription.setText(Html.fromHtml(newsItem.getDescription()));

        Cursor cursor = context.getContentResolver().query(PhotosColumns.CONTENT_URI, null,
                PhotosColumns.TASK_ID + " LIKE ?", new String[] { "" + newsItem.getDatabaseId() }, null);

        if (cursor != null) {
            List<String> photos = new ArrayList<>(cursor.getCount());

            while (cursor.moveToNext()) {
                photos.add(cursor.getString(cursor.getColumnIndex(PhotosColumns.URL)));
            }
            cursor.close();
            newsItem.setPhoto(photos);
        }

    } else {
        // If there is no outside intent - fetch example photos
        List<String> dummyPhotos = new ArrayList<>();
        dummyPhotos.addAll(Arrays.asList(getResources().getStringArray(R.array.task_image_links)));

        newsItem = new TaskItem();
        newsItem.setPhoto(dummyPhotos);
    }

    // To boost performance as we know that size won't change
    mRecyclerView.setHasFixedSize(true);

    // Horizontal LayoutManager
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false);

    mRecyclerView.setLayoutManager(layoutManager);

    // Adapter with data about different activities
    PhotoAdapter photoAdapter = new PhotoAdapter(newsItem.getPhoto(), context, this);
    mRecyclerView.setAdapter(photoAdapter);

    return rootView;
}

From source file:com.squareup.leakcanary.AbstractAnalysisResultService.java

@Override
protected final void onHandleIntentInForeground(@Nullable Intent intent) {
    if (intent == null) {
        CanaryLog.d("AbstractAnalysisResultService received a null intent, ignoring.");
        return;/*w  ww.  j  a va2 s  . c  o  m*/
    }
    if (!intent.hasExtra(ANALYZED_HEAP_PATH_EXTRA)) {
        onAnalysisResultFailure(getString(R.string.leak_canary_result_failure_no_disk_space));
        return;
    }
    File analyzedHeapFile = new File(intent.getStringExtra(ANALYZED_HEAP_PATH_EXTRA));
    AnalyzedHeap analyzedHeap = AnalyzedHeap.load(analyzedHeapFile);
    if (analyzedHeap == null) {
        onAnalysisResultFailure(getString(R.string.leak_canary_result_failure_no_file));
        return;
    }
    try {
        onHeapAnalyzed(analyzedHeap);
    } finally {
        //noinspection ResultOfMethodCallIgnored
        analyzedHeap.heapDump.heapDumpFile.delete();
        //noinspection ResultOfMethodCallIgnored
        analyzedHeap.selfFile.delete();
    }
}

From source file:me.willowcheng.makerthings.core.OpenHABVoiceService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "onHandleIntent()");
    bufferIntent(intent);//from   w  w w. j  av a 2 s  .  co m
    if (intent.hasExtra(OPENHAB_BASE_URL_EXTRA)) {
        Log.d(TAG, "openHABBaseUrl passed as Intent");
        onOpenHABTracked(intent.getStringExtra(OPENHAB_BASE_URL_EXTRA), null);
    } else if (mOpenHABTracker == null) {
        Log.d(TAG, "No openHABBaseUrl passed, starting OpenHABTracker");
        mOpenHABTracker = new OpenHABTracker(OpenHABVoiceService.this, getString(R.string.openhab_service_type),
                false);
        mOpenHABTracker.start();
    }
}

From source file:com.apptentive.android.sdk.Apptentive.java

/**
 * Determines whether a push was sent by Apptentive. Apptentive push notifications will result in an Intent
 * containing a string extra key of {@link Apptentive#APPTENTIVE_PUSH_EXTRA_KEY}.
 *
 * @param intent The push notification Intent you received in your BroadcastReceiver.
 * @return True if the Intent contains Apptentive push information.
 *//*from w  ww .jav a2 s  .c  o  m*/
public static boolean isApptentivePushNotification(Intent intent) {
    if (intent != null) {
        if (intent.getAction() != null && intent.getAction().equals("com.apptentive.PUSH")) {
            // This came from Parse.
            return true;
        }
        if (intent.hasExtra(Apptentive.APPTENTIVE_PUSH_EXTRA_KEY)) {
            // This came from another push provider.
            return true;
        }
    }
    return false;
}

From source file:com.hybris.mobile.activity.OrderDetailActivity.java

private void handleIntent(Intent intent) {

    if (Hybris.isUserLoggedIn()) {
        if (intent.hasExtra("orderDetails")) {
            ((TextView) findViewById(R.id.lbl_thankYou)).setVisibility(View.VISIBLE);
            ((TextView) findViewById(R.id.lbl_orderConfirmation)).setVisibility(View.VISIBLE);
            // TODO
            setmOrderDetails(JsonUtils.fromJson(intent.getStringExtra("orderDetails"), CartOrder.class));
        }//from  w w w . j av a  2  s  .co m
        if (intent.hasExtra(DataConstants.ORDER_ID)) {
            setmOrderID(intent.getStringExtra(DataConstants.ORDER_ID));
        }
        // Call from another application (QR Code) 
        else if (StringUtils.equals(intent.getAction(), Intent.ACTION_VIEW)) {
            setmOrderID(RegexUtil.getOrderIdFromHybrisPattern(intent.getDataString()));
        }
    }
    // User not logged in, redirection to the login page
    else {
        Intent loginIntent = new Intent(this, LoginActivity.class);

        // Call from another application (QR Code) 
        if (StringUtils.equals(intent.getAction(), Intent.ACTION_VIEW)) {
            loginIntent.putExtra(DataConstants.ORDER_ID,
                    RegexUtil.getOrderIdFromHybrisPattern(intent.getDataString()));
        }

        loginIntent.putExtra(DataConstants.INTENT_DESTINATION, DataConstants.INTENT_ORDER_DETAILS);
        loginIntent.putExtras(intent);
        startActivity(loginIntent);
    }
}

From source file:com.szanata.cordova.phonestatechangelistener.PhoneStateChangeListener.java

/**
 * creates a new BroadcastReceiver to listen whether the Telephony State changes
 *//*from  w w  w .  j  av a 2s.co  m*/
public void startPhoneListener(final CallbackContext callbackContext) {

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

            @Override
            public void onReceive(final Context context, final Intent intent) {

                if (intent != null && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
                    String state = intent.hasExtra(TelephonyManager.EXTRA_STATE)
                            ? intent.getStringExtra(TelephonyManager.EXTRA_STATE)
                            : NONE;
                    String number = "";

                    if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                        number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
                    }

                    final JSONObject data = new JSONObject();
                    try {
                        data.put("state", state);
                        data.put("number", number);
                        callbackContext.success(data);
                    } catch (final JSONException e) {
                        callbackContext.error(e.getMessage());
                    }

                }
            }
        };

        this.context.registerReceiver(this.receiver,
                new IntentFilter(TelephonyManager.ACTION_PHONE_STATE_CHANGED));
    }
}