Example usage for android.content Intent setData

List of usage examples for android.content Intent setData

Introduction

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

Prototype

public @NonNull Intent setData(@Nullable Uri data) 

Source Link

Document

Set the data this intent is operating on.

Usage

From source file:com.ryan.ryanreader.fragments.InboxListingFragment.java

private void handleClick(RedditPreparedInboxItem item) {
    if (item instanceof RedditPreparedComment) {
        final URI commentContext = Constants.Reddit.getUri(((RedditPreparedComment) item).src.context);

        final Intent intent = new Intent(getSupportActivity(), CommentListingActivity.class);
        intent.setData(Uri.parse(commentContext.toString()));
        startActivity(intent);// w  ww  .  j  a v a2 s. c om
    }
}

From source file:at.ac.uniklu.mobile.sportal.WebViewActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*  www  .j  ava2  s  .  c om*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String targetUrl = getIntent().getStringExtra(URL);
    if (targetUrl == null || targetUrl.length() == 0) {
        // if there's no URL, close the activity
        finish();
    }

    setContentView(R.layout.webview);
    mActionBar = new ActionBarHelper(this).setupHeader().addActionRefresh();

    // set header title or hide header if no title is given
    String title = getIntent().getStringExtra(TITLE);
    if (title != null) {
        ((TextView) findViewById(R.id.view_title)).setText(title);
    } else {
        findViewById(R.id.actionbar).setVisibility(View.GONE);
    }

    // Moodle 2.0 uses SSO/CAS authentication
    mSSO = getIntent().getBooleanExtra(SSO, false);

    // the moodle hack is only needed until Android 2.3 (or maybe 3.x? - not tested)
    // Android 4.0 has the redirect history entry problem solved
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        mExecuteMoodleHack = getIntent().getBooleanExtra(MOODLE_HACK, false);
    }

    mWebView = (WebView) findViewById(R.id.web_view);
    //mWebView.setBackgroundColor(Color.BLACK); // black color messes up the CAS login page
    mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); // http://stackoverflow.com/questions/3998916/android-webview-leaves-space-for-scrollbar
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setLightTouchEnabled(true);
    mWebView.getSettings().setLoadWithOverviewMode(true);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.getSettings().setUseWideViewPort(true);

    // setup custom webview client that shows a progress dialog while loading
    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith("https://sso.uni-klu.ac.at") || url.startsWith("https://sso.aau.at")
                    || url.startsWith("https://campus.aau.at") || url.startsWith("https://moodle.aau.at")) {
                return false;
            } else if (url.startsWith("http://campus-gis.aau.at/")) {
                Log.d(TAG, "REDIRECT TO MAP");
                String roomParameter = "curRouteTo=";
                int index = url.indexOf(roomParameter);
                if (index > -1) {
                    MapUtils.openMapAndShowRoom(WebViewActivity.this,
                            url.substring(index + roomParameter.length()));
                }
                return true;
            }

            // open external websites in browser
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
            return true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            progressNotificationOn();
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
            progressNotificationOff();
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressNotificationOff();

            /*
             *  the first page of moodle opens through a redirect so we need to clear the first history
             *  entry to avoid execution of the redirect when going back through the history with the back button
             */
            if (mExecuteMoodleHack && mWebView.canGoBack()) {
                mWebView.clearHistory();
                mExecuteMoodleHack = false;
            } else {
                mIsFirstPage = false;
            }
        }
    });

    mWebView.setDownloadListener(new DownloadListener() {
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            Analytics.onEvent(Analytics.EVENT_WEB_COURSEMOODLE_DOWNLOAD);
            Uri uri = Uri.parse(url);
            MoodleDownloadHelper.download(WebViewActivity.this, uri,
                    Utils.getContentDispositionOrUrlFilename(contentDisposition, uri));
        }
    });

    // set session cookie
    // http://stackoverflow.com/questions/1652850/android-webview-cookie-problem
    // http://android.joao.jp/2010/11/cookiemanager-and-removeallcookie.html
    if (Studentportal.getSportalClient().isSessionCookieAvailable()) {
        CookieSyncManager.createInstance(this);
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        //cookieManager.removeSessionCookie(); // NOTE when calling this method the cookies get removed after the next setCookie() gets called

        Cookie sessionCookie = Studentportal.getSportalClient().getSessionCookie();
        cookieManager.setCookie(sessionCookie.getDomain(), Utils.cookieHeaderString(sessionCookie));

        if (mSSO) {
            // set SSO/CAS cookie
            Cookie ssoCookie = Studentportal.getSportalClient().getCookie("CASTGC");
            if (ssoCookie != null) {
                cookieManager.setCookie(ssoCookie.getDomain(), Utils.cookieHeaderString(ssoCookie));
            }
        }

        CookieSyncManager.getInstance().sync();
    }

    mIsFirstPage = true;
    mWebView.loadUrl(targetUrl);
}

From source file:com.ProfessorPopTart.alternateouyastore.MainActivity.java

/**
 * This will start the download of the apk file
 *
 * @param urlResults  String JSON response form the download url request
 */// w ww  .  j  av a 2 s .  co m
private void downloadApk(String urlResults) {
    String link = getLink(urlResults);
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(link));
    startActivity(i);
}

From source file:com.netatmo.weatherstation.sample.LoginActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent browserIntent = new Intent();
    browserIntent.setAction(Intent.ACTION_VIEW);

    switch (item.getItemId()) {
    case R.id.action_forgot_password:
        browserIntent.setData(Uri.parse("https://auth.netatmo.com/access/lostpassword"));
        startActivity(browserIntent);/*from w w w . j  a va2 s . c o  m*/
        return true;
    case R.id.action_create_account:
        browserIntent.setData(Uri.parse("https://auth.netatmo.com/access/signup"));
        startActivity(browserIntent);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.drunkenhamster.facerecognitionfps.SnapFaceActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    if (calledACTION_GET_CONTENT_) {
        if (resultCode == RESULT_OK && data != null) {
            Uri uri = data.getData();/*from ww  w .  j a v a2  s . c om*/
            Intent intent = new Intent();
            intent.setData(uri);
            setResult(RESULT_OK, intent);
            tracker_.trackEvent(getString(R.string.GA_CAT_ACT), getString(R.string.GA_ACT_GET_CONTENT),
                    getString(R.string.GA_LBL_SUCCEED), 1);
        }
        setResult(resultCode);
        finish();
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.miz.functions.TmdbTrailerSearch.java

@Override
protected void onPostExecute(String result) {
    if (result != null) {
        if (YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(mActivity)
                .equals(YouTubeInitializationResult.SUCCESS)) {
            Intent intent = YouTubeStandalonePlayer.createVideoIntent(mActivity,
                    MizLib.getYouTubeApiKey(mActivity), MizLib.getYouTubeId(result), 0, false, true);
            mActivity.startActivity(intent);
        } else {//from   w  w w . j a  v a 2s .  c o  m
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(result));
        }
    } else {
        new YoutubeTrailerSearch(mActivity, mSearchQuery).execute();
    }
}

From source file:com.bluelinelabs.logansquare.typeconverters.IntentConverter.java

@Override
public Intent parse(JsonParser jsonParser) throws IOException {
    SimpleIntent simpleIntent = SimpleIntent$$JsonObjectMapper._parse(jsonParser);
    Intent intent = new Intent();

    android.util.Log.d("json2notification", "action:" + simpleIntent.action);
    if (simpleIntent.action != null) {
        intent.setAction(simpleIntent.action);
    }//  w  ww  . j a va 2  s  .c o m
    android.util.Log.d("json2notification", "uri:" + simpleIntent.uri);
    if (simpleIntent.uri != null) {
        intent.setData(simpleIntent.uri);
    }
    return intent;
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToWebSessionObj.java

public void handleDirectMessage(Context context, Contact from, JSONObject obj) {
    String arg = obj.optString(ARG);
    Intent launch = new Intent();
    launch.setAction(Intent.ACTION_MAIN);
    launch.addCategory(Intent.CATEGORY_LAUNCHER);
    launch.putExtra("android.intent.extra.APPLICATION_ARGUMENT", arg);
    launch.putExtra("creator", false);
    launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    String webUrl = obj.optString(WEB_URL);
    launch.setData(Uri.parse(webUrl));
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch,
            PendingIntent.FLAG_CANCEL_CURRENT);
    (new PresenceAwareNotify(context)).notify("New Invitation", "Invitation received",
            "Click to launch application.", contentIntent);
}

From source file:org.kegbot.app.service.CheckinService.java

/**
 * Processes the checkin response message.
 */// ww w  .  ja v a2s.c o m
private void processLastCheckinResponse(JsonNode response) {
    Log.d(TAG, "Checkin response: " + response);

    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    final JsonNode statusNode = response.get("status");
    if (statusNode == null || !statusNode.isTextual()) {
        Log.d(TAG, "Invalid checkin response: no status.");
        return;
    }

    final String status = statusNode.getTextValue();
    if (STATUS_OK.equals(status)) {
        Log.d(TAG, "Checkin status: " + status);
    } else {
        Log.d(TAG, "Invalid checkin response: unknown status: " + status);
        return;
    }

    boolean updateNeeded = false;
    final JsonNode updateNeededNode = response.get("update_needed");
    if (updateNeededNode != null && updateNeededNode.isBoolean() && updateNeededNode.getBooleanValue()) {
        updateNeeded = true;
    }

    boolean updateRequired = false;
    final JsonNode updateRequiredNode = response.get("update_required");
    if (updateRequiredNode != null && updateRequiredNode.isBoolean() && updateRequiredNode.getBooleanValue()) {
        updateRequired = true;
    }

    mPrefsHelper.setLastCheckinStatus(status);
    mPrefsHelper.setUpdateNeeded(updateNeeded);
    mPrefsHelper.setUpdateRequired(updateRequired);

    if (updateNeeded) {
        Intent notificationIntent = new Intent(Intent.ACTION_VIEW);
        notificationIntent.setData(Uri.parse("market://details?id=org.kegbot.app"));
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        int titleRes = updateRequired ? R.string.checkin_update_required_title
                : R.string.checkin_update_available_title;

        Notification noti = new Notification.Builder(this)
                .setSmallIcon(updateRequired ? R.drawable.icon_warning : R.drawable.icon_download)
                .setContentTitle(getString(titleRes))
                .setContentText(getString(R.string.checkin_update_description)).setContentIntent(contentIntent)
                .setOngoing(true).setOnlyAlertOnce(true).getNotification();

        Log.d(TAG, "Posting notification.");
        nm.notify(CHECKIN_NOTIFICATION_ID, noti);
    } else {
        nm.cancel(CHECKIN_NOTIFICATION_ID);
    }
}

From source file:it.gulch.linuxday.android.services.AlarmIntentService.java

private PendingIntent getAlarmPendingIntent(long eventId) {
    Intent intent = new Intent(this, AlarmReceiver.class);
    intent.setAction(AlarmReceiver.ACTION_NOTIFY_EVENT);
    intent.setData(Uri.parse(String.valueOf(eventId)));

    return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}