Android Deeplink如何使用现有的Activity来处理Intent?

时间:2015-09-24 18:33:52

标签: android android-intent deep-linking

我有一个显示名人和一些信息的活动。

清单中的声明:

  <activity
            android:name=".CelebrityActivity"
            android:configChanges="orientation|screenSize"
            android:label="@string/title_activity_celebrities"
            android:launchMode="singleInstance"
            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:scheme="some_scheme" />
            </intent-filter>
        </activity>

关注this guide

  

例如,以下命令会尝试查看与指定URI关联的目标应用活动。

 $ adb shell am start
    -W -a android.intent.action.VIEW
    -d "example://gizmos" com.example.android

我的问题是当我执行 adb命令(您在上面看到)时,它会立即重新创建我的活动,甚至会启动活动。

我尝试添加launchMode:singleInstance标志,但是......没有变化。活动也会重新创建。

所以我的问题是如何处理现有活动中的结果

1 个答案:

答案 0 :(得分:0)

我相信你需要使用

BrokeredMessage receivedMessage = Client.Receive(TimeSpan.FromSeconds(10));
if (receivedMessage != null && receivedMessage.ContentType == "Authors")
{
    Uri uri = new Uri(CloudConfigurationManager.GetSetting("Sharepoint.Uri"));
    Office365ClaimsHelper claimsHelper = new Office365ClaimsHelper(uri, CloudConfigurationManager.GetSetting("Sharepoint.User"),                            CloudConfigurationManager.GetSetting("Sharepoint.Password"));
    using (ClientContext context = new ClientContext(uri))
    {
        context.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;
        AuthorWrapper author = GetAuthorFromMessage(receivedMessage);                
        string title = CloudConfigurationManager.GetSetting("Sharepoint.ListName");
        List authorsList = context.Web.Lists.GetByTitle(title);
        context.Load(authorsList);
        context.ExecuteQuery(); // THIS LINE
        // do some other stuff, including adding the author to the list
     }
     receivedMessage.Complete();
}

而不是adb shell am broadcast -a "android.intent.action.VIEW" -d "some_scheme://" 。链接由android框架作为广播处理。