下面列出了android.content.Intent#ACTION_VIEW 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
}
@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();
}
@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;
}
}
@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);
}
}
@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;
}
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);
}
/**
* 跳转到官网
**/
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();
}
}
/**
* 打开音频资源
* @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);
}
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;
}
/**
* 安装应用
*
* @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;
}
/**
* 安装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);
}
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;
}
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);
}
public void doPositiveClickExternal(String url) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
}
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);
}
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);
}
public void openWebsite() {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(MainActivity.WEBSITE + "/forum-post?id=" + this.instance.id));
startActivity(intent);
}
@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);
}
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;
}
/**
* 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);
}