Java Code Examples for android.content.Intent#ACTION_VIEW

The following examples show how to use android.content.Intent#ACTION_VIEW . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static void sideloadInstall(Context ctx, String assetFilename) {
    Log.d(TAG, "sideloadInstall: About to install app " + assetFilename);
    try {
        // Read .pbw from assets/
        Intent intent = new Intent(Intent.ACTION_VIEW);
        File file = new File(ctx.getExternalFilesDir(null), assetFilename);
        InputStream is = ctx.getResources().getAssets().open(assetFilename);
        OutputStream os = new FileOutputStream(file);
        byte[] pbw = new byte[is.available()];
        is.read(pbw);
        os.write(pbw);
        is.close();
        os.close();

        // Install via Pebble Android app
        intent.setDataAndType(Uri.fromFile(file), "application/pbw");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        ctx.startActivity(intent);
    } catch (IOException e) {
        Toast.makeText(ctx, "App install failed: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
    }
}
 
Example 2
Source Project: 365browser   File: SearchActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void loadUrl(String url) {
    // Wait until native has loaded.
    if (!mIsActivityUsable) {
        mQueuedUrl = url;
        return;
    }

    // Don't do anything if the input was empty. This is done after the native check to prevent
    // resending a queued query after the user deleted it.
    if (TextUtils.isEmpty(url)) return;

    // Fix up the URL and send it to the full browser.
    String fixedUrl = UrlFormatter.fixupUrl(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(fixedUrl));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    intent.setClass(this, ChromeLauncherActivity.class);
    IntentHandler.addTrustedIntentExtras(intent);
    IntentUtils.safeStartActivity(this, intent,
            ActivityOptionsCompat
                    .makeCustomAnimation(this, android.R.anim.fade_in, android.R.anim.fade_out)
                    .toBundle());
    RecordUserAction.record("SearchWidget.SearchMade");
    finish();
}
 
Example 3
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.loginButton:
            if (isPrivacyAccepted) {
                if (isEmailValid(emailEditText.getText().toString())) {
                    loginUser(emailEditText.getText().toString());
                }
            } else {
                Toast.makeText(this, R.string.terms_and_privacy_error, Toast.LENGTH_SHORT)
                        .show();
            }
            break;
        case R.id.copyrightLayout:
            Intent intent = new Intent(
                    Intent.ACTION_VIEW,
                    Uri.parse(getResources().getString(R.string.website_url)));
            startActivity(intent);
            break;
    }
}
 
Example 4
Source Project: intra42   File: UserOverviewFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    if (v == layoutPhone) {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse("tel:" + user.phone));
        startActivity(intent);
    } else if (v == imageButtonSMS) {
        Intent sendIntent = new Intent(Intent.ACTION_VIEW);
        sendIntent.setData(Uri.parse("sms:" + user.phone));
        startActivity(sendIntent);
    } else if (v == layoutMail) {
        Intent testIntent = new Intent(Intent.ACTION_VIEW);
        Uri data = Uri.parse("mailto:?to=" + user.email);
        testIntent.setData(data);
        startActivity(testIntent);
    } else if (v == layoutLocation) {
        LocationHistoryActivity.openItWithUser(getContext(), user);
    } else if (v == buttonFriend) {
        ApiService42Tools api = app.getApiService42Tools();

        setButtonFriends(0);
        if (isFriend == null)
            return;
        if (!isFriend) { //add
            Call<Friends> friendsCall = api.addFriend(user.id);
            friendsCall.enqueue(addFriend);
            Analytics.friendAdd();
        } else {
            api.deleteFriend(user.id).enqueue(removeFriend);
            Analytics.friendRemove();
        }
    } else if (v == imageViewProfile) {
        ImageViewerActivity.openIt(getContext(), user);
    }
}
 
Example 5
Source Project: ParallaxScroll   File: SingleParallaxListView.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	if (item.getItemId() == R.id.action_github) {
		Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/nirhart/ParallaxScroll"));
		startActivity(browserIntent);
	}
	return true;
}
 
Example 6
Source Project: CoolClock   File: FuncUnit.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void openURL(Context c, String url) {
    if (url == null)
        return;
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    c.startActivity(intent);
}
 
Example 7
/**
 * 跳转到官网
 **/
private void gotoWebsite(String url) {
    try {
        Uri uri = Uri.parse("http://" + url);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        new CommonDialog(this, "提示信息", "检测到您没有可用的浏览器,请先安装!", "确定").show();
    }

}
 
Example 8
Source Project: FileManager   File: FileUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 打开音频资源
 * @param context
 * @param file
 */
public static void openMusicIntent( Context context , File file ){
    Uri path = Uri.fromFile(file);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setDataAndType(path, "audio/*");
    context.startActivity(intent);
}
 
Example 9
Source Project: iBeebo   File: Utility.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static boolean isGooglePlaySafe(Activity activity) {
    Uri uri = Uri.parse("http://play.google.com/store/apps/details?id=com.google.android.gms");
    Intent mapCall = new Intent(Intent.ACTION_VIEW, uri);
    mapCall.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
    mapCall.setPackage("com.android.vending");
    PackageManager packageManager = activity.getPackageManager();
    List<ResolveInfo> activities = packageManager.queryIntentActivities(mapCall, 0);
    return activities.size() > 0;
}
 
Example 10
/**
 * 安装应用
 *
 * @param context
 * @param filePath
 * @return
 */
public static boolean installApk(Context context, String filePath) {
    File file = new File(filePath);
    if (!file.exists() || !file.isFile() || file.length() <= 0) {
        return false;
    }
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
    return true;
}
 
Example 11
Source Project: qingyang   File: UpdateManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 安装apk
 */
private void installApk() {
	File apkFile = new File(apkFilePath);

	if (!apkFile.exists()) {
		return;
	}
	Intent i = new Intent(Intent.ACTION_VIEW);
	i.setDataAndType(Uri.parse("file://" + apkFile.toString()),
			"application/vnd.android.package-archive");
	context.startActivity(i);
}
 
Example 12
Source Project: AppPlus   File: IntentHelper.java    License: MIT License 5 votes vote down vote up
static Intent createIntentForGooglePlay(Context context) {
    String packageName = context.getPackageName();
    Intent intent = new Intent(Intent.ACTION_VIEW, getGooglePlay(packageName));
    if (isPackageExists(context, GOOGLE_PLAY_PACKAGE_NAME)) {
        intent.setPackage(GOOGLE_PLAY_PACKAGE_NAME);
    }
    return intent;
}
 
Example 13
Source Project: Kore   File: AbstractInfoFragment.java    License: Apache License 2.0 4 votes vote down vote up
protected void playItemLocally(String url, String type) {
    Uri uri = Uri.parse(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    intent.setDataAndType(uri, type);
    startActivity(intent);
}
 
Example 14
public void doPositiveClickExternal(String url) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    startActivity(i);
}
 
Example 15
Source Project: FlyWoo   File: ChatAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private void openFile(View v, File f) {
    Intent it = new Intent(Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(f);
    it.setDataAndType(uri, "*/*");
    v.getContext().startActivity(it);
}
 
Example 16
Source Project: droidddle   File: Utils.java    License: Apache License 2.0 4 votes vote down vote up
public static String getShotViewIntent(Shot shot) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(shot.htmlUrl));
    return intent.toUri(Intent.URI_INTENT_SCHEME);
}
 
Example 17
public void openWebsite() {
	Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MainActivity.WEBSITE + "/forum-post?id=" + this.instance.id));
	startActivity(intent);
}
 
Example 18
Source Project: call_manage   File: AboutActivity.java    License: MIT License 4 votes vote down vote up
@OnClick(R.id.about_bugs)
public void openBugReporting(View v) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.app_bug_reporting_url)));
    startActivity(intent);
}
 
Example 19
Source Project: sms-ticket   File: App.java    License: Apache License 2.0 4 votes vote down vote up
public static Intent getOpenMarketIntent(Context context) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse("market://details?id=" + context.getPackageName()));
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return i;
}
 
Example 20
/**
 * Triggers an intent to open the Spotify accounts service in a browser. Make sure that the
 * redirectUri is set to an URI your app is registered for in your AndroidManifest.xml. To
 * get your clientId and to set the redirectUri, please see the
 * <a href="https://developer.spotify.com/my-applications">my applications</a>
 * part of our developer site.
 *
 * @param contextActivity The activity that should start the intent to open a browser.
 * @param request         Authorization request
 */
public static void openLoginInBrowser(Activity contextActivity, AuthorizationRequest request) {
    Intent launchBrowser = new Intent(Intent.ACTION_VIEW, request.toUri());
    contextActivity.startActivity(launchBrowser);
}