【问题标题】:Android How to get values from deep link in android using java? [duplicate]Android 如何使用java从android中的深层链接获取值? [复制]
【发布时间】:2019-05-16 22:31:17
【问题描述】:

Android 如何使用 java 从 android 中的深层链接获取值? 我正在我的 android 应用程序中实现深层链接,现在我想获取所有参数,比如在斜线之后。 我的网址 = www.exmple.com/poduct-name/prodcut_id

www.example.com/iphone/147895

所以我想从上面的 url 获取 id-147895?

【问题讨论】:

    标签: java android deep-linking


    【解决方案1】:

    试试这个——

     URI uri = new URI("www.exmple.com/iphone/147895");
     String[] spPath= uri.getPath().split("/");
     String idStr = spPath[spPath.length-1];
     int id = Integer.parseInt(idStr);
    

    谢谢

    【讨论】:

    • 它不工作
    • 请检查编辑。
    【解决方案2】:

    对于您要开始深度链接处理的activity,请将此意图过滤器放在清单中的<activity>...</activity> 中,如下所示:

    <intent-filter>
          <action android:name="android.intent.action.VIEW"/>
          <category android:name="android.intent.category.BROWSABLE"/>
          <category android:name="android.intent.category.DEFAULT"/>
          <data
              android:host="www.example.com"
              android:pathPattern="/.*"
              android:scheme="https"/>
     </intent-filter>
    

    然后在您的活动中,如果它被标记为“singleTask”,您将能够在onNewIntent(Intent intent) 方法中从意图中获取数据,或者如果它被标记为“newTask”,您应该在onCreate(...) 并通过调用 getIntent() 方法获取意图。解析过程将是这样的, 1.对于onCreate():

    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
       setContentView(R.layout.your_view);
       if (getIntent() != null && getIntent().getData() != null)
       {
          //parse your data here,
          //it's the deeplink you want "https://www.example.com/..."
       }
    }
    
    1. 对于 newIntent()

      protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (intent != null && intent.getData() != null) { //在这里解析你的数据, //这是你想要的深层链接“https://www.example.com/...” } }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多