다른 앱의 Twitter 앱에서 페이지 열기-Android
웹뷰없이 트위터 앱을 시작하고 내 애플리케이션에서 지정된 페이지를 여는 방법을 찾고있었습니다. 여기에서 Facebook에 대한 해결책을 찾았습니다 : 지정된 프로필 페이지에서 Facebook 앱 열기
비슷한 것이 필요합니다.
편집 방금 해결책을 찾았습니다.
try {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("twitter://user?screen_name=[user_name]"));
startActivity(intent);
} catch (Exception e) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://twitter.com/#!/[user_name]")));
}
이것은 나를 위해 일했습니다. twitter://user?user_id=id_num
ID를 확인하려면 : http://www.idfromuser.com/
fg.radigales 답변에 따르면 가능한 경우 앱을 시작하는 데 사용한 것이지만 그렇지 않으면 브라우저로 돌아갑니다.
Intent intent = null;
try {
// get the Twitter app if possible
this.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USERID"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch (Exception e) {
// no Twitter app, revert to browser
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/PROFILENAME"));
}
this.startActivity(intent);
최신 정보
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
트위터가 새 활동이 아닌 내 앱 내에서 열리는 문제를 수정하기 위해 추가되었습니다 .
Android를 사용하는 다른 앱에서 Twitter 앱의 페이지를 2 단계로 엽니 다.
1. 아래 코드를 붙여 넣기 만하면됩니다 (버튼 클릭 또는 필요한 곳에).
Intent intent = null;
try{
// Get Twitter app
this.getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USER_ID"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} catch () {
// If no Twitter app found, open on browser
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/USERNAME"));
}
2.intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=USER_ID"));
USER_ID를 얻으려면 사용자 이름 http://gettwitterid.com/을 작성 하고 거기에 Twitter 사용자 ID를 얻으십시오.
참조 : https://solutionspirit.com/open-page-twitter-application-android/
도움이 되길 바랍니다 :)
내 답변은 fg.radigales와 Harry의 널리 받아 들여지는 답변을 기반으로합니다. 사용자가 Twitter를 설치했지만 비활성화 한 경우 (예 : 앱 격리 사용)이 방법은 작동하지 않습니다. Twitter 앱의 인 텐트가 선택되지만 비활성화되어 있으므로 처리 할 수 없습니다.
대신에:
getPackageManager().getPackageInfo("com.twitter.android", 0);
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=2343965036"));
다음을 사용하여 수행 할 작업을 결정할 수 있습니다.
PackageInfo info = getPackageManager().getPackageInfo("com.twitter.android", 0);
if(info.applicationInfo.enabled)
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("twitter://user?user_id=2343965036"));
else
intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/wrkoutapp"));
이 코드 조각을 시도하십시오. 그것은 당신을 도울 것입니다.
//Checking If the app is installed, according to the package name
Intent intent = new Intent();
intent.setType("text/plain");
intent.setAction(Intent.ACTION_SEND);
final PackageManager packageManager = getPackageManager();
List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : list)
{
String packageName = resolveInfo.activityInfo.packageName;
//In case that the app is installed, lunch it.
if (packageName != null && packageName.equals("com.twitter.android"))
{
try
{
String formattedTwitterAddress = "twitter://user/" ;
Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress));
long twitterId = <Here is the place for the twitter id>
browseTwitter.putExtra("user_id", twitterId);
startActivity(browseTwitter);
return;
}
catch (Exception e)
{
}
}
}
//If it gets here it means that the twitter app is not installed. Therefor, lunch the browser.
try
{
String twitterName = <Put the twitter name here>
String formattedTwitterAddress = "http://twitter.com/" + twitterName;
Intent browseTwitter = new Intent(Intent.ACTION_VIEW, Uri.parse(formattedTwitterAddress));
startActivity(browseTwitter);
}
catch (Exception e)
{
}
나를 위해 이것은 당신이 가지고 있거나 웹 브라우저로 가면 트위터 앱을 여는 트릭을했습니다.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/"+"USERID"));
startActivity(intent);
참고URL : https://stackoverflow.com/questions/11105103/open-page-in-twitter-app-from-other-app-android
'Development Tip' 카테고리의 다른 글
예외 처리는 언제 어떻게 사용해야합니까? (0) | 2020.10.24 |
---|---|
NuGet-repositories.config (0) | 2020.10.24 |
TypeScript로 배열 항목을 어떻게 찾습니까? (0) | 2020.10.24 |
파이썬 소스 코드를 읽고 싶습니다. (0) | 2020.10.24 |
동일한 ASP.NET MVC 작업에 대한 여러 동시 AJAX 호출로 인해 브라우저가 차단되는 이유는 무엇입니까? (0) | 2020.10.24 |