Example usage for android.content Intent ACTION_VIEW

List of usage examples for android.content Intent ACTION_VIEW

Introduction

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

Prototype

String ACTION_VIEW

To view the source code for android.content Intent ACTION_VIEW.

Click Source Link

Document

Activity Action: Display the data to the user.

Usage

From source file:im.delight.android.baselib.Social.java

/**
 * Opens the given user's Facebook profile
 *
 * @param context Context instance to get the PackageManager from
 * @param facebookID the user's Facebook ID
 *//*from ww  w. j a  va2 s.  com*/
public static void openFacebookProfile(Context context, String facebookID) {
    Intent intent;
    try {
        context.getPackageManager().getPackageInfo("com.facebook.katana", 0); // throws exception if not installed
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/" + facebookID));
    } catch (Exception e) {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + facebookID));
    }
    try {
        context.startActivity(intent);
    } catch (Exception e) {
    }
}

From source file:com.badlogic.gdx.backends.android.AndroidNet.java

@Override
public void openURI(String URI) {
    if (app == null) {
        Gdx.app.log("AndroidNet", "Can't open browser activity from livewallpaper");
        return;//from   w ww.  j a v  a 2 s.co m
    }
    final Uri uri = Uri.parse(URI);
    app.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            app.startActivity(new Intent(Intent.ACTION_VIEW, uri));
        }
    });
}

From source file:bolts.AppLinkTest.java

public void testSimpleIntent() throws Exception {
    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));

    assertEquals(i.getData(), AppLinks.getTargetUrl(i));
    assertNull(AppLinks.getAppLinkData(i));
    assertNull(AppLinks.getAppLinkExtras(i));
}

From source file:it.uniroma2.foundme.studente.CourseActivity.java

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

    context = this;

    course = (TextView) findViewById(R.id.tvNameCoures);
    prof = (TextView) findViewById(R.id.tvNameProf);
    ass1 = (TextView) findViewById(R.id.tvNameAss1);
    ass2 = (TextView) findViewById(R.id.tvNameAss2);
    msg = (Button) findViewById(R.id.btnMsg);

    notifica = (Switch) findViewById(R.id.switch_notif);

    imgUniroma2 = (ImageButton) findViewById(R.id.imageButton);

    Bundle passed = getIntent().getExtras();
    Data = passed.getString(Variables_it.COURSE);
    extractData(Data);//from  w w w.  ja  v  a2s. c  om

    pref = SPEditor.init(CourseActivity.this.getApplicationContext());
    Sid = SPEditor.getID(pref);

    try {
        manageInfo(Title, Prof, Sid);
    } catch (ExecutionException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    imgUniroma2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Variables_it.SITE_TV));
            startActivity(browserIntent);
        }
    });

    msg.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {
            Intent i = new Intent(CourseActivity.this, ReadMessageActivity.class);
            i.putExtra(Variables_it.COURSE, Title);
            i.putExtra(Variables_it.ID, Sid);
            startActivity(i);
        }
    });
}

From source file:fr.bmartel.android.iotf.app.ConnectActivity.java

protected void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);
    setContentView(R.layout.activity_connect);

    final Intent intent = getIntent();

    String defaultOrgId = "";
    String defaultApiKey = "";
    String defaultApiToken = "";

    if (BuildConfig.BLUEMIX_IOT_ORG != null)
        defaultOrgId = BuildConfig.BLUEMIX_IOT_ORG;
    if (BuildConfig.BLUEMIX_API_KEY != null)
        defaultApiKey = BuildConfig.BLUEMIX_API_KEY;
    if (BuildConfig.BLUEMIX_API_TOKEN != null)
        defaultApiToken = BuildConfig.BLUEMIX_API_TOKEN;

    String organizationId = sharedpreferences.getString(StorageConst.STORAGE_ORGANIZATION_ID, defaultOrgId);
    String apiKey = sharedpreferences.getString(StorageConst.STORAGE_API_KEY, defaultApiKey);
    String apiToken = sharedpreferences.getString(StorageConst.STORAGE_API_TOKEN, defaultApiToken);
    boolean ssl = sharedpreferences.getBoolean(StorageConst.STORAGE_USE_SSL, true);

    boolean fromJsonFile = false;

    if (Intent.ACTION_VIEW.equals(intent.getAction())) {

        String jsonContent = loadFile(intent);

        try {/*from   w ww  .  j  a  v a 2 s  .  c  o  m*/
            JSONObject json = new JSONObject(jsonContent);

            if (json.has(StorageConst.STORAGE_API_KEY) && json.has(StorageConst.STORAGE_API_TOKEN)
                    && json.has(StorageConst.STORAGE_ORGANIZATION_ID)
                    && json.has(StorageConst.STORAGE_USE_SSL)) {

                organizationId = json.getString(StorageConst.STORAGE_ORGANIZATION_ID);
                apiKey = json.getString(StorageConst.STORAGE_API_KEY);
                apiToken = json.getString(StorageConst.STORAGE_API_TOKEN);
                ssl = json.getBoolean(StorageConst.STORAGE_USE_SSL);

                SharedPreferences.Editor editor = sharedpreferences.edit();
                editor.putString(StorageConst.STORAGE_ORGANIZATION_ID, organizationId);
                editor.putString(StorageConst.STORAGE_API_KEY, apiKey);
                editor.putString(StorageConst.STORAGE_API_TOKEN, apiToken);
                editor.putBoolean(StorageConst.STORAGE_USE_SSL, ssl);
                editor.commit();

                fromJsonFile = true;

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    ScrollView scrollView = (ScrollView) findViewById(R.id.scrollview);

    mOrganizationEditText = (EditText) scrollView.findViewById(R.id.organization);
    mApikeyEditText = (EditText) scrollView.findViewById(R.id.api_key);
    mApitokenEditText = (EditText) scrollView.findViewById(R.id.api_token);
    mOrganizationEditText.setText(organizationId);
    mApikeyEditText.setText(apiKey);
    mApitokenEditText.setText(apiToken);
    mSslCheckbox = (CheckBox) scrollView.findViewById(R.id.ssl);
    mSslCheckbox.setChecked(ssl);
    mReconnectCheckbox = (CheckBox) scrollView.findViewById(R.id.reconnect);
    mReconnectCheckbox.setChecked(true);

    if (fromJsonFile) {
        connect();
    }

    initNv();
}

From source file:com.google.android.apps.chrometophone.GCMIntentService.java

@Override
public void onMessage(Context context, Intent intent) {
    Bundle extras = intent.getExtras();/*from w w w .j  ava2s  . c  o m*/
    if (extras != null) {
        String url = (String) extras.get("url");
        String title = (String) extras.get("title");
        String sel = (String) extras.get("sel");
        String debug = (String) extras.get("debug");

        if (debug != null) {
            // server-controlled debug - the server wants to know
            // we received the message, and when. This is not user-controllable,
            // we don't want extra traffic on the server or phone. Server may
            // turn this on for a small percentage of requests or for users
            // who report issues.
            DefaultHttpClient client = new DefaultHttpClient();
            HttpGet get = new HttpGet(AppEngineClient.BASE_URL + "/debug?id=" + extras.get("collapse_key"));
            // No auth - the purpose is only to generate a log/confirm delivery
            // (to avoid overhead of getting the token)
            try {
                client.execute(get);
            } catch (ClientProtocolException e) {
                // ignore
            } catch (IOException e) {
                // ignore
            }
        }

        if (title != null && url != null && url.startsWith("http")) {
            SharedPreferences settings = Prefs.get(context);
            Intent launchIntent = LauncherUtils.getLaunchIntent(context, title, url, sel);

            // Notify and optionally start activity
            if (settings.getBoolean("launchBrowserOrMaps", true) && launchIntent != null) {
                LauncherUtils.playNotificationSound(context);
                LauncherUtils.sendIntentToApp(context, launchIntent);
            } else {
                LauncherUtils.generateNotification(context, url, title, launchIntent);
            }

            // Record history (for link/maps only)
            if (launchIntent != null && launchIntent.getAction().equals(Intent.ACTION_VIEW)) {
                HistoryDatabase.get(context).insertHistory(title, url);
            }
        }
    }
}

From source file:com.appnexus.opensdk.ANJAMImplementation.java

private static void callDeepLink(WebView webView, Uri uri) {
    String cb = uri.getQueryParameter("cb");
    String urlParam = uri.getQueryParameter("url");

    LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>();
    list.add(new BasicNameValuePair(KEY_CALLER, CALL_DEEPLINK));

    if ((webView.getContext() == null) || (urlParam == null)) {
        loadResult(webView, cb, list);// w  w  w .ja  v a 2s.  c  om
        return;
    }
    try {
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Uri.decode(urlParam)));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        webView.getContext().startActivity(intent);
    } catch (ActivityNotFoundException e) {
        loadResult(webView, cb, list);
    }
}

From source file:de.netfutura.phonegap.plugin.MapLauncher.java

private boolean doOpen(String location, CallbackContext callbackContext) {
    boolean result;
    try {//w w w . ja va 2s.co m
        String logMsg = "Navigating to " + location;
        String url;

        url = String.format(Locale.ENGLISH, "geo:%f", location);

        Log.d(LOG_TAG, logMsg);

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

        this.cordova.getActivity().startActivity(intent);
        result = true;
    } catch (Exception e) {
        String msg = e.getMessage();
        if (msg.contains(NO_GOOGLE_NAVIGATOR)) {
            msg = "Google Navigator app is not installed on this device";
        }
        Log.e(LOG_TAG, "Exception occurred: ".concat(msg));
        callbackContext.error(msg);
        result = false;
    }
    return result;
}

From source file:com.kakao.KakaoLink.java

/**
 *  ? ??    ./*from   w  ww  . j  a  v  a 2  s  .  co  m*/
 * @param linkMessage     contents
 * @param context ?  context
 */
public void sendMessage(final String linkMessage, final Context context) throws KakaoParameterException {
    final Intent intent = TalkProtocol.createKakakoTalkLinkIntent(context, linkMessage);
    if (intent == null) {
        //alert install dialog
        new AlertDialog.Builder(context).setIcon(android.R.drawable.ic_dialog_alert)
                .setMessage(context.getString(string.com_kakao_alert_install_kakaotalk))
                .setPositiveButton(android.R.string.ok, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        context.startActivity(new Intent(Intent.ACTION_VIEW,
                                Uri.parse(KakaoTalkLinkProtocol.TALK_MARKET_URL_PREFIX + makeReferrer())));
                    }
                }).create().show();

    } else {
        context.startActivity(intent);
    }
}

From source file:me.sandrin.xkcdwidget.XKCDAppWidgetProvider.java

private void updateRemoteViews(Context context, RemoteViews views) {
    if (title != null) {
        views.setTextViewText(R.id.title, title);
    }/*from  w  ww  . j  a  v  a  2  s.c  o  m*/

    if (image != null) {
        views.setImageViewBitmap(R.id.image, image);
    } else {
        views.setImageViewBitmap(R.id.image, null);
    }

    Intent goToSiteIntent = new Intent(Intent.ACTION_VIEW);
    goToSiteIntent.setData(Uri.parse("http://xkcd.com"));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, goToSiteIntent, 0);
    views.setOnClickPendingIntent(R.id.image, pendingIntent);

    if (altText != null) {
        views.setTextViewText(R.id.alt_text, altText);
    }

    Intent intent = new Intent(context, getClass());
    intent.setAction(UPDATE);
    views.setOnClickPendingIntent(R.id.sync, PendingIntent.getBroadcast(context, 0, intent, 0));
}