Java Code Examples for android.content.Intent.ACTION_VIEW

The following are Jave code examples for showing how to use ACTION_VIEW of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: android-dev-challenge   File: MainActivity.java   View Source Code Vote up 9 votes
/**
 * This method will fire off an implicit Intent to view a location on a map.
 *
 * When constructing implicit Intents, you can use either the setData method or specify the
 * URI as the second parameter of the Intent's constructor,
 * as I do in {@link #openWebPage(String)}
 *
 * @param geoLocation The Uri representing the location that will be opened in the map
 */
private void showMap(Uri geoLocation) {
    /*
     * Again, we create an Intent with the action, ACTION_VIEW because we want to VIEW the
     * contents of this Uri.
     */
    Intent intent = new Intent(Intent.ACTION_VIEW);

    /*
     * Using setData to set the Uri of this Intent has the exact same affect as passing it in
     * the Intent's constructor. This is simply an alternate way of doing this.
     */
    intent.setData(geoLocation);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}
 
Example 2
Project: appinventor-extensions   File: ResultHandler.java   View Source Code Vote up 8 votes
final void openURL(String url) {
  // Strangely, some Android browsers don't seem to register to handle HTTP:// or HTTPS://.
  // Lower-case these as it should always be OK to lower-case these schemes.
  if (url.startsWith("HTTP://")) {
    url = "http" + url.substring(4);
  } else if (url.startsWith("HTTPS://")) {
    url = "https" + url.substring(5);
  }
  Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
  try {
    launchIntent(intent);
  } catch (ActivityNotFoundException anfe) {
    Log.w(TAG, "Nothing available to handle " + intent);
  }
}
 
Example 3
Project: Camera-warner   File: MapsActivity.java   View Source Code Vote up 8 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemID = item.getItemId();

    switch (itemID) {
        case R.id.action_settings:
            Intent mapsActivity = new Intent(this, SettingsActivity.class);
            startActivity(mapsActivity);
            return true;
        case R.id.action_add:
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://juvenal.org"));
            startActivity(browserIntent);
    }

    return super.onOptionsItemSelected(item);
}
 
Example 4
Project: lqrwechatrongcloud   File: FileOpenUtils.java   View Source Code Vote up 7 votes
/**
 * 调用自带的音频播放器
 *
 * @param context
 * @param path
 */
private static void openAudio(Context context, String path) {
    File f = new File(path);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.fromFile(f), "audio/*");// "audio/mp3"
    context.startActivity(intent);
}
 
Example 5
Project: 19porn   File: Kits.java   View Source Code Vote up 7 votes
/**
 * 安装App
 *
 * @param context
 * @param filePath
 * @return
 */
public static boolean installNormal(Context context, String filePath) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    java.io.File file = new java.io.File(filePath);
    if (file == null || !file.exists() || !file.isFile() || file.length() <= 0) {
        return false;
    }

    i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
    return true;
}
 
Example 6
Project: AndroidApp-Deploy   File: MainActivity.java   View Source Code Vote up 6 votes
public void premiumsport2(View view){
    String videoUrl = "http://178.33.226.36:8000/live/olsi/olsi/1176.ts";
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(videoUrl));
    startActivity(i);
}
 
Example 7
Project: CoolCloud-Weather   File: AboutApplicationActivity.java   View Source Code Vote up 6 votes
@Override
public void onClick(View v) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    switch (v.getId()){
        case R.id.github:
            intent.setData(Uri.parse("http://Github.com/LynnYuki"));
            break;
        case R.id.blog:
            intent.setData(Uri.parse("https://lynnyuki.github.io"));
            break;
    }
    startActivity(intent);
}
 
Example 8
Project: Renrentou   File: Kits.java   View Source Code Vote up 6 votes
/**
 * 安装App
 *
 * @param context
 * @param filePath
 * @return
 */
public static boolean installNormal(Context context, String filePath) {
    Intent i = new Intent(Intent.ACTION_VIEW);
    java.io.File file = new java.io.File(filePath);
    if (file == null || !file.exists() || !file.isFile() || file.length() <= 0) {
        return false;
    }

    i.setDataAndType(Uri.parse("file://" + filePath), "application/vnd.android.package-archive");
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);
    return true;
}
 
Example 9
Project: Tribe   File: EaseShowVideoActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
			WindowManager.LayoutParams.FLAG_FULLSCREEN);
	setContentView(R.layout.ease_showvideo_activity);
	loadingLayout = (RelativeLayout) findViewById(R.id.loading_layout);
	progressBar = (ProgressBar) findViewById(R.id.progressBar);

	final EMMessage message = getIntent().getParcelableExtra("msg");
	if (!(message.getBody() instanceof EMVideoMessageBody)) {
		Toast.makeText(EaseShowVideoActivity.this, "Unsupported message body", Toast.LENGTH_SHORT).show();
		finish();
		return;
	}
	EMVideoMessageBody messageBody = (EMVideoMessageBody)message.getBody();

	localFilePath = messageBody.getLocalUrl();

	if (localFilePath != null && new File(localFilePath).exists()) {
		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.setDataAndType(Uri.fromFile(new File(localFilePath)),
				"video/mp4");
		startActivity(intent);
		finish();
	} else {
		EMLog.d(TAG, "download remote video file");
		downloadVideo(message);
	}
}
 
Example 10
Project: PlayAndroid   File: WebViewActivity.java   View Source Code Vote up 6 votes
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition,
                            String mimetype, long contentLength) {
    Log.d(TAG, "onDownloadStart() called with: url = [" + url + "], userAgent = [" +
            userAgent + "], contentDisposition = [" + contentDisposition + "], " +
            "mimetype = [" + mimetype + "], contentLength = [" + contentLength + "]");
    try {
        Uri uri = Uri.parse(url);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 11
Project: Android-SmartWebView   File: IntentHelper.java   View Source Code Vote up 6 votes
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 12
Project: Trinity-App   File: MainActivity.java   View Source Code Vote up 6 votes
public void openInstagram(View view) {
    Uri uri = Uri.parse("https://instagram.com/_u/trinity.djsce/");
    Intent likeIng = new Intent(Intent.ACTION_VIEW, uri);

    likeIng.setPackage("com.instagram.android");

    try {
        startActivity(likeIng);
    } catch (ActivityNotFoundException e) {
        startActivity(new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://instagram.com/trinity.djsce/")));
    }
}
 
Example 13
Project: tvConnect_android   File: CaptureActivityHandler.java   View Source Code Vote up 5 votes
@Override
public void handleMessage(Message message) {
	if (message.what == R.id.restart_preview) {
		restartPreviewAndDecode();

	} else if (message.what == R.id.decode_succeeded) {
		state = State.SUCCESS;
		Bundle bundle = message.getData();
		Bitmap barcode = null;
		float scaleFactor = 1.0f;
		if (bundle != null) {
			byte[] compressedBitmap = bundle
					.getByteArray(DecodeThread.BARCODE_BITMAP);
			if (compressedBitmap != null) {
				barcode = BitmapFactory.decodeByteArray(compressedBitmap,
						0, compressedBitmap.length, null);
				// Mutable copy:
				barcode = barcode.copy(Bitmap.Config.ARGB_8888, true);
			}
			scaleFactor = bundle
					.getFloat(DecodeThread.BARCODE_SCALED_FACTOR);
		}
		activity.handleDecode((Result) message.obj, barcode, scaleFactor);

	} else if (message.what == R.id.decode_failed) {// We're decoding as fast as possible, so when one decode fails,
		// start another.
		state = State.PREVIEW;
		cameraManager.requestPreviewFrame(decodeThread.getHandler(),
				R.id.decode);

	} else if (message.what == R.id.return_scan_result) {
		activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
		activity.finish();

	} else if (message.what == R.id.launch_product_query) {
		String url = (String) message.obj;

		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
		intent.setData(Uri.parse(url));

		ResolveInfo resolveInfo = activity.getPackageManager()
				.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
		String browserPackageName = null;
		if (resolveInfo != null && resolveInfo.activityInfo != null) {
			browserPackageName = resolveInfo.activityInfo.packageName;
			Log.d(TAG, "Using browser in package " + browserPackageName);
		}

		// Needed for default Android browser / Chrome only apparently
		if ("com.android.browser".equals(browserPackageName)
				|| "com.android.chrome".equals(browserPackageName)) {
			intent.setPackage(browserPackageName);
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			intent.putExtra(Browser.EXTRA_APPLICATION_ID,
					browserPackageName);
		}

		try {
			activity.startActivity(intent);
		} catch (ActivityNotFoundException ignored) {
			Log.w(TAG, "Can't find anything to handle VIEW of URI " + url);
		}

	}
}
 
Example 14
Project: IslamicLibraryAndroid   File: AboutUtil.java   View Source Code Vote up 5 votes
private static void openMarket(Context context, String appURI, String webURI) {
    // you can also use BuildConfig.APPLICATION_ID
    //String appId = "com.google.android.apps.books";
    Intent rateIntent = new Intent(Intent.ACTION_VIEW,
            Uri.parse(appURI));
    boolean marketFound = false;

    // find all applications able to handle our rateIntent
    final List<ResolveInfo> otherApps = context.getPackageManager()
            .queryIntentActivities(rateIntent, 0);
    for (ResolveInfo otherApp : otherApps) {
        // look for Google Play application
        if (otherApp.activityInfo.applicationInfo.packageName
                .equals("com.android.vending")) {

            ActivityInfo otherAppActivity = otherApp.activityInfo;
            ComponentName componentName = new ComponentName(
                    otherAppActivity.applicationInfo.packageName,
                    otherAppActivity.name
            );
            // make sure it does NOT open in the stack of your activity
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            // task re-parenting if needed
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
            // if the Google Play was already open in a search result
            //  this make sure it still go to the app page you requested
            rateIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            // this make sure only the Google Play app is allowed to
            // intercept the intent
            rateIntent.setComponent(componentName);
            context.startActivity(rateIntent);
            marketFound = true;
            break;

        }
    }

    // if GP not present on device, open web browser
    if (!marketFound) {
        Intent webIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(webURI));
        context.startActivity(webIntent);
    }
}
 
Example 15
Project: SpaceRace   File: CreditsActivity.java   View Source Code Vote up 5 votes
@OnClick(R.id.facebook)
public void goOnFacebookPage() {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(FACEBOOK_URI));
    startActivity(browserIntent);
}
 
Example 16
Project: MovieApp   File: PeopleExternalLinksWrapper.java   View Source Code Vote up 5 votes
private Intent browserIntent(String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(url));
    return intent;
}
 
Example 17
Project: aftercare-app-android   File: DCUtils.java   View Source Code Vote up 5 votes
public static void openURL(Context context, String url) {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    context.startActivity(browserIntent);
}
 
Example 18
Project: RLibrary   File: IntentUtils.java   View Source Code Vote up 5 votes
/**
 * 获取其他应用组件的意图
 *
 * @param packageName 包名
 * @param className   全类名
 * @param bundle      bundle
 * @return intent
 */
public static Intent getComponentIntent(String packageName, String className, Bundle bundle) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    if (bundle != null) intent.putExtras(bundle);
    ComponentName cn = new ComponentName(packageName, className);
    intent.setComponent(cn);
    return intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
 
Example 19
Project: FriendBook   File: UpdateService.java   View Source Code Vote up 5 votes
private static Intent webLauncher(String downloadUrl) {
    Uri download = Uri.parse(downloadUrl);
    Intent intent = new Intent(Intent.ACTION_VIEW, download);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    return intent;
}
 
Example 20
Project: PlusGram   File: MarkersActivity.java   View Source Code Vote up 5 votes
public void clickMarketLink(View unused) {
    hideOverflow();
    Intent urlIntent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("market://details?id=" + getPackageName()));
    startActivity(urlIntent);
}