특정 URL을 열기 위해 브라우저에 인 텐트 보내기 [중복]
이 질문에 이미 답변이 있습니다.
특정 URL을 열고 표시하기 위해 휴대 전화의 브라우저에 인 텐트를 실행하는 방법이 궁금합니다.
누군가 나에게 힌트를 줄 수 있습니까?
URL / 웹 사이트를 열려면 다음을 수행하십시오.
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
다음 은Intent.ACTION_VIEW
.
출처 : 애플리케이션 내에서 Android 웹 브라우저에서 URL 열기
짧은 버전
Intent i = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://almondmendoza.com/android-applications/"));
startActivity(i);
잘 작동합니다 ...
가장 짧은 버전.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")));
경우에 따라 URL이 "www"로 시작할 수 있습니다. 이 경우 예외가 발생합니다.
android.content.ActivityNotFoundException: No Activity found to handle Intent
URL은 항상 "http : //"또는 "https : //"로 시작해야하므로 다음 코드를 사용합니다.
if (!url.startsWith("https://") && !url.startsWith("http://")){
url = "http://" + url;
}
Intent openUrlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(openUrlIntent);
특정 URL을 열기 위해 브라우저에 인 텐트 보내기 :
String url = "https://www.stackoverflow.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
짧은 코드 버전으로 변경 될 수 있습니다 ...
Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://www.stackoverflow.com"));
startActivity(intent);
또는
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com"));
startActivity(intent);
또는 더 짧습니다!
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.stackoverflow.com")));
의도 에 대한 추가 정보
=)
표시 할 Google지도에 좌표를 직접 전달하는 방법도 있습니까?
geo URI
접두사를 사용할 수 있습니다 .
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:" + latitude + "," + longitude));
startActivity(intent);
XML에서
보기에 웹 주소 / URL이 표시되어 있고이를 클릭 할 수있게 만들고 사용자를 특정 웹 사이트로 연결하려는 경우 다음을 사용할 수 있습니다.
android:autoLink="web"
같은 방법으로 autoLink (이메일, 전화,지도, 모두)의 다른 속성을 사용하여 작업을 수행 할 수 있습니다.
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
startActivity(browserIntent);
코드에서 다음 스 니펫 사용
Intent newIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.google.co.in/?gws_rd=cr"));
startActivity(newIntent);
이 링크 사용
http://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW
"Google지도에 좌표를 직접 전달하여 표시하는 방법도 있습니까?"
I have found that if I pass a URL containing the coords to the browser, Android asks if I want the browser or the Maps app, as long as the user hasn't chosen the browser as the default. See my answer here for more info on the formating of the URL.
I guess if you used an intent to launch the Maps App with the coords, that would work also.
참고URL : https://stackoverflow.com/questions/3004515/sending-an-intent-to-browser-to-open-specific-url
'programing tip' 카테고리의 다른 글
개체 목록 섞기 (0) | 2020.09.30 |
---|---|
값이 목록에 있는지 확인하는 가장 빠른 방법 (0) | 2020.09.30 |
람다 (함수) 란? (0) | 2020.09.30 |
SQL Server의 DateTime2 대 DateTime (0) | 2020.09.30 |
JavaScript로 브라우저 뷰포트 크기 가져 오기 (0) | 2020.09.30 |