我在http://developers.google.com/+/mobile/android/share/deep-link上尝试使用Google+中的深层链接到Android应用.
我可以分享到Google+.帖子中的链接是"可点击的"(在触摸期间突出显示),但在发布时不做任何操作.此外,帖子包含可疑的"未定义"文本行.
样本http://raw.github.com/concreterose/TestDeepLink/master/README_ASSETS/sample_share.png
我在Google Developers Console项目凭据中启用了深层链接.
我正在使用使用Scopes.PLUS_LOGIN创建的已登录PlusClient,通过以下方式发布:
Intent shareIntent = new PlusShare.Builder(this, plusClient)
.setText("Testing deep link")
.setType("text/plain")
.setContentDeepLinkId("deeplink",
"title",
"description",
Uri.parse(thumbnailUrl))
.getIntent();
startActivityForResult(shareIntent, 0);
Run Code Online (Sandbox Code Playgroud)
我不确定我是否需要所有这些,同时试图让我的工作变得有效:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
Run Code Online (Sandbox Code Playgroud)
处理活动(作为清单中的第一个活动):
<activity android:name=".ParseDeepLinkActivity">
<intent-filter>
<action android:name="com.google.android.apps.plus.VIEW_DEEP_LINK" />
<data android:scheme="vnd.google.deeplink" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
是:
public class ParseDeepLinkActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate");
throw new RuntimeException("got here");
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用发布密钥库构建并在运行4.4的几个真实设备上进行测试. …
情况:
TL; DR - 你如何实现这个?
我的方法到目前为止:
第一直觉:只匹配某些网址并为其启动.问题:AndroidManifest intent-filter中表达式的缺乏阻止了这一点(例如http://weiyang.wordpress.ncsu.edu/2013/04/11/a-limitation-in-intent-filter-of-android-application/) .
作为问题的一个子集,假设m.somewhere.com上的服务器知道任何以数字结尾的URL都会进入网站上的某个页面,并且营销人员会不断地使用seo,所以例如,
我想推出以下应用:
http://m.somewhere.com/find/abc-12345
https://m.somewhere.com/shop/xyz-45678928492
Run Code Online (Sandbox Code Playgroud)
但不是
http://m.somewhere.com/find/abc-12345-xyz
https://m.somewhere.com/about-us
Run Code Online (Sandbox Code Playgroud)
没有path,pathPrefix或pathPattern的组合将处理此问题.
stackoverflow的最佳实践(在AndroidManifest中匹配URI与<data>一样http://example.com/something)似乎是要抓住所有内容,然后在你进入onCreate()时意识到你不应该有这种情况处理了这个特殊的网址:
Android清单:
...
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="m.somewhere.com"
android:pathPattern=".*"/>
</intent-filter>
...
Run Code Online (Sandbox Code Playgroud)
活动onCreate():
Intent i = getIntent()
String action = i.getAction();
Uri uri = i.getData();
if (Intent.ACTION_VIEW.equals(action) && cantHandleUrl(uri)) {
// TODO - fallback to browser.
}
Run Code Online (Sandbox Code Playgroud)
我已经编写了类似于上面的东西,但它会导致非常糟糕的最终用户体验:
可以做些什么?
(编辑:在应用程序的WebView中显示未处理页面的站点不是一个选项).
当从移动浏览器网站进入Android应用程序的深层链接,然后我按下后退按钮,应用程序关闭,后台没有任何东西,而不是去移动浏览器网站.当我点击所有打开的应用程序的设备按钮时,我看到浏览器仍然在内存中,因此我认为操作系统不会清除浏览器.有人解决了这个问题吗?请帮忙.
我需要安装一个没有安装我的应用程序的iOS用户,然后自动导航到我的应用程序中的一部分.
相关的是这个问题,但我并不完全依赖Google的SDK.我可以用任何东西.
我怎么能够
我在清单中定义了以下内容:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.package">
...
<activity
android:name="app.myActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.example.com"
android:pathPrefix="/gizmos"
android:scheme="http" />
<!-- note that the leading "/" is required for pathPrefix-->
<!-- Accepts URIs that begin with "example://gizmos”-->
<data
android:host="gizmos"
android:scheme="example" />
</intent-filter>
</activity>
...
Run Code Online (Sandbox Code Playgroud)
我已经定义了我的onCreate():
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Uri data = intent.getData();
if (data != null) {
Log.d("URI",data.toString());
}
}
Run Code Online (Sandbox Code Playgroud)
这符合Android文档:Android Deep Linking
所以问题是:
如何测试URI深层链接?根据文档我运行的东西
adb shell …
我在我的应用程序中使用应用程序索引,但有时它无法正确接收来自Chrome的意图.
如果我从我的生产网站打开链接,它将由chrome打开.所以我创建了一个具有相同代码的测试站点.但是,在这种情况下,我的应用正确打开深层链接.
我找不到任何解释,因为它在网络中使用相同的代码(但在不同的网站中)和相同的Android应用程序.
这是我的意图过滤器:
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="soriabus-web.appspot.com" android:pathPrefix="/" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
这是我的按钮中的html代码:
<a href="https://soriabus-web.appspot.com/parada/1/plaza-mariano-granados/true"
"type="button"
role="button"
class="btn btn-primary">
Abrir Soria Bus
</a>
Run Code Online (Sandbox Code Playgroud)
如果我打开此地址(制作)中的链接,则会打开Play商店(链接的末尾是重定向到Google Play):
https://soriabus-web.appspot.com/parada/1/plaza-mariano-granados
如果我在这个其他地址(测试)中打开链接,它会打开我的app correclty:
https://central-splice-128620.appspot.com/parada/1/plaza-mariano-granados
我不明白为什么链接处理不同.谢谢.
编辑:
是因为我正在关注同一网站内的链接吗?
https://soriabus-web.appspot.com/parada/1/plaza-mariano-granados => https://soriabus-web.appspot.com/parada/1/plaza-mariano-granados/playstore
android deep-linking intentfilter android-app-indexing firebase-app-indexing
我找不到单个文档来解释如何在段中使用可选参数.
在我的app.module.ts中,我有这个deepLinkConfig:
let deepLinkConfig = {
links: [{
component: HomePage, name: 'Home', segment: 'home'
}, {
component: ConnexionPage, name: 'Connexion', segment: 'connexion'
}, {
component: InscriptionPage, name: 'Inscription', segment: 'inscription'
}, {
component: ProfilePage, name: 'Profile', segment: 'profile/:userId'
}, {
component: ExplorePage, name: 'Explore', segment: 'explore'
}, {
component: FAQPage, name: 'FAQ', segment: 'faq'
}]
};
...
imports: [
...
IonicModule.forRoot(MyApp, {}, deepLinkConfig);
],
Run Code Online (Sandbox Code Playgroud)
用户应该能够通过访问他的个人资料/profile,但也可以咨询其他用户的个人资料/profile/:userId.但是当我尝试访问/配置文件时,我收到一个错误:
未捕获(承诺):要插入的视图无效
通过navCtrl,可以使用空字符串作为userId转到'profile',但是一旦你实现了页面,它就会变成空白.
有没有办法让深层链接中的参数可选?
有太多深层链接(通用链接或应用链接)教程.但其中大多数都展示了如何在Android或IOS应用中启用它.此外还有付费云解决方案,但它们提供了许多功能.但是我在现实生活中面临三个主要问题:
我写了这个Q&A,这是我学习的结果(花了太多时间),以便有一个独特的,适用于所有案例的解决方案.
代码来自我的工作解决方案,但我删除了一些部分只是为了表明这个想法.如果存在一些编译问题,请按照算法编写自己的代码
这是解决方案,即使你知道一些步骤也要一步一步,因为代码中有技巧.还有一些解释在代码部分的注释行中,请阅读它们.
示例是使用最终的参数处理Android和IOS应用程序的深层链接http://example.com/v/,例如http://example.com/v/id-of-user?key=value.
1.配置Android
1.1将活动信息添加到AndroidManifest.xml文件中:
<activity
android:name=".appLinkHandlerActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="example.com"
android:pathPrefix="/v/"
android:scheme="http" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!—this intent is needed to handle links to myapp://share, I will explain later why we need it -->
<data
android:host="share"
android:scheme="myapp" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
1.2创建名为appLinkHandlerActivity的活动,该活动将处理单击的链接
public class appLinkHandlerActivity extends AppCompatActivity {
/* assume that user is clicked http://example.com/v/my-user-id
actCode will be …Run Code Online (Sandbox Code Playgroud) 我按照本指南 - Splash屏幕以正确的方式为我的Android应用程序创建了一个Splash屏幕,所以现在我有2个活动(MainActivity和SplashActivity)
问题是Deep Links错过现在的行为,而不是启动MainActivity它们启动它SplashActivity.
SplashActivity除了应用程序启动时,我不希望它出现.
我能做什么?
SplashActivity:
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
Run Code Online (Sandbox Code Playgroud)
主要活动:
public class MainActivity extends SplashActivity implements OnImagePickerPermissionsCallback {
private PermissionListener listener;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void setPermissionListener(PermissionListener listener)
{
this.listener = listener;
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
{
if …Run Code Online (Sandbox Code Playgroud) java android deep-linking android-manifest react-native-navigation
我有我的Android应用程序(react-native为基础)和深度链接第一次当我运行它而应用程序没有在后台运行时效果很好,但当应用程序在后台运行时我点击深层链接它甚至没有打开应用程序...我不确定从哪里开始这个错误我console.logs在生命周期事件中尝试了一些,但他们甚至没有运行.
请指导我在哪里寻找问题以及如何解决它,谢谢!
deep-linking ×10
android ×6
adb ×1
angular ×1
app-store ×1
applinks ×1
browser ×1
deeplink ×1
facebook ×1
google-plus ×1
intentfilter ×1
ionic3 ×1
ios ×1
java ×1
objective-c ×1
react-native ×1