【发布时间】:2015-03-25 07:43:41
【问题描述】:
如果应用程序安装在智能手机上,我需要知道如何让链接打开应用程序中的 Instagram 页面。
www.instagram.com/example 这样的简单方式通过浏览器将您链接到页面,这不是我想要的。
我如何做到这一点?
【问题讨论】:
如果应用程序安装在智能手机上,我需要知道如何让链接打开应用程序中的 Instagram 页面。
www.instagram.com/example 这样的简单方式通过浏览器将您链接到页面,这不是我想要的。
我如何做到这一点?
【问题讨论】:
试试这个:
工作 100% <a href="instagram://user?username=untitled.tiff">untitled.tiff</a>
【讨论】:
从浏览器启动 Instagram。 要以链接形式启动 instagram,只需提供如下链接即可:
<a href="http://instagram.com/p/<picture id>">look at this instagram picture</a>
示例:look at this instagram picture
<a href="http://instagram.com/p/0nUyKnMJw4">look at this instagram picture</a>
尝试在安卓设备上打开该链接。另外,请记住必须在设备上安装 Instagram。 对于用户,将“p”替换为“_u”,将图片 id 替换为用户名。
为什么会这样? instagram 应用程序有一个用于 http 和 https 浏览的意图监听器
<data android:host="instagram.com" android:pathPrefix="/p/" android:scheme="http"/>
<data android:host="instagram.com" android:pathPrefix="/p/" android:scheme="https"/>
<data android:host="instagram.com" android:pathPrefix="/_u/" android:scheme="http"/>
<data android:host="instagram.com" android:pathPrefix="/_u/" android:scheme="https"/>
<data android:host="instagram.com" android:pathPrefix="/_uid/" android:scheme="http"/>
<data android:host="instagram.com" android:pathPrefix="/_uid/" android:scheme="https"/>
<data android:host="instagram.com" android:pathPrefix="/_n/" android:scheme="http"/>
<data android:host="instagram.com" android:pathPrefix="/_n/" android:scheme="https"/>
编辑:看来我有一个旧的 Manifest 文件。
【讨论】:
www.instagram.com/_u/example 代替www.instagram.com/example。你的意图看起来像这样startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.instagram.com/_u/example/")));
它对我有用。
try {
// mediaLink is something like "https://instagram.com/p/6GgFE9JKzm/" or
// "https://instagram.com/_u/sembozdemir"
Uri uri = Uri.parse(mediaLink);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setPackage("com.instagram.android");
startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.e(TAG, e.getMessage());
}
【讨论】:
您可以通过浏览器锚链接上的 android 意图打开。您可以获取详细信息here
<a href="intent://instagram.com/#Intent;package=com.instagram.android;scheme=https;end">Open Instagram</a>
【讨论】:
我认为您最好的选择是使用 Intent,您可以使用 Intent 发送数据,使用 Intent(短意图)“广播”消息,并且正在监听它的应用程序会响应。
将其视为我发送给我的一群朋友的电子邮件,如果我要求 mark 做某事,mark 会回复,但其他人会忽略该电子邮件。
您可以使用此代码发送意图(此代码特定于您的问题,但可以轻松编辑以满足其他需求):
Intent insta_intent = getPackageManager().getLaunchIntentForPackage("com.instagram.android");
insta_intent.setComponent(new ComponentName("com.instagram.android", "com.instagram.android.activity.UrlHandlerActivity"));
//use this if you want to open an image
insta_intent.setData(Uri.parse("http://instagram.com/p/gjfLqSBQTJ/"));
//And if you want to open a user's profile use this
insta_intent.setData(Uri.parse("http://instagram.com/_u/USER"));
startActivity(insta_intent);
【讨论】:
你可以试试这个方法。您可以通过 Instagram 或浏览器让 POPUP 选择打开链接。 (此方法用于您想要的任何链接,而不仅仅是 Instagram。)
***.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = "Your URL";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
});
【讨论】: