특정 URL을 열기 위해 브라우저로 의도 보내기
저는 특정 URL을 열고 표시하기 위해 전화기의 브라우저에 인텐트를 어떻게 실행하는지 궁금합니다.
누가 저에게 힌트를 줄 수 있나요?
URL/웹 사이트를 열려면 다음을 수행합니다.
String url = "http://www.example.com";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
다음은 의 설명서입니다.
출처: 애플리케이션 내에서 Android의 웹 브라우저에서 URL 열기
짧은 버전
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://almondmendoza.com/android-applications/")));
역시 효과가 있을 겁니다...
가장 짧은 버전.
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")));
Android 11+ 버전용 업데이트:
다음 코드를 추가합니다.manifest
파일
<application>
......
.....
</application>
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>
경우에 따라 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")));
의도에 대한 자세한 정보
=)
구글 지도에 직접 좌표를 전달하여 표시하는 방법도 있습니까?
지역을 사용할 수 있습니다. URI
접두사:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("geo:" + latitude + "," + longitude));
startActivity(intent);
원본 XML
웹 주소/URL을 보기에 표시하여 클릭 가능하게 하고 사용자가 특정 웹 사이트로 이동하기를 원하는 경우 다음을 사용할 수 있습니다.
android:autoLink="web"
마찬가지로 자동 링크의 다른 속성(이메일, 전화, 지도, 모두)을 사용하여 작업을 수행할 수 있습니다.
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
"또한 구글 지도에 직접 좌표를 전달하여 표시하는 방법이 있습니까?"
브라우저에 좌표가 포함된 URL을 전달하면 사용자가 브라우저를 기본값으로 선택하지 않은 한 안드로이드에서 브라우저를 원하는지 지도 앱을 원하는지 묻는 것을 발견했습니다.URL 형식에 대한 자세한 내용은 여기에서 제 답변을 참조하십시오.
좌표와 함께 지도 앱을 실행하려는 의도를 사용했다면 그것도 효과가 있을 것이라고 생각합니다.
언급URL : https://stackoverflow.com/questions/3004515/sending-an-intent-to-browser-to-open-specific-url
'source' 카테고리의 다른 글
Python의 "Private"(구현) 클래스 (0) | 2023.07.18 |
---|---|
도커 로컬 환경 사용자 지정 로컬 도메인(호스트 파일?) (0) | 2023.07.13 |
MS Visual Studio: How to exclude certain Project Folders from publishing? (0) | 2023.07.13 |
DDL 문은 항상 암묵적 커밋을 제공합니까? 아니면 암묵적 롤백을 제공할 수 있습니까? (0) | 2023.07.13 |
MongoDB 복제에 'arbitter'가 필요한 이유는 무엇입니까? (0) | 2023.07.13 |