2017-03-02 90 views
2
Android deep linking is not working 
=================================== 
Android link:-notification://id=notificationid 

1: - 在清單Android的深層鏈接無法正常工作

 <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 

        <category android:name="android.intent.category.LAUNCHER" /> 
        <category android:name="android.intent.category.BROWSABLE" /> 

        <data 
         android:host="id" 
         android:scheme="notification" /> 
       </intent-filter>  

2: - 和編碼側

@Override 
     protected void onResume() { 
      super.onResume();   
      Intent intent = getIntent(); 
      String string=intent.getAction(); 
      Uri data = intent.getData(); 
      Log.d("hello","cgbdsuyfdkv"); 
     } 

,但它不工作,請任何機構可以幫助我! !

+0

是您的代碼第一次運行? –

+0

是運行我的代碼和我的網址這樣(通知:// id = notificationid)但它可以不能工作 –

+0

但第二次你無法獲得更新通知ID?右 –

回答

0

你可以簡單地修改網址

Android link:-notification://id=notificationid instead of 
Android link:-notification://page?id=notificationid //page is host name 
I tried a lot and find out this is working for me. 
  1. 清單代碼

      <intent-filter> 
          <action android:name="android.intent.action.VIEW" /> 
          <category android:name="android.intent.category.LAUNCHER" /> 
          <category android:name="android.intent.category.BROWSABLE" /> 
    
          <data 
           android:host="page" 
           android:scheme="notification" /> 
         </intent-filter>  
    

2 .java代碼#請在此處註冊您的通知ID

Intent intent = getIntent(); 
    String string = intent.getAction(); 
    Uri data = intent.getData(); 
    if (data != null) { 
     String path = data.getPath(); 
     String path1 = data.getPath(); 
     providerUrl = intent.getData().toString(); 
     UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(); 
     sanitizer.setAllowUnregisteredParamaters(true); 
     sanitizer.parseUrl(providerUrl); 
     String id = sanitizer.getValue("id"); 
     if (id != null) 
      Log.d("notification id", id); 
    } 
+0

是的,我同意 我的Android鏈接: - **通知:// id = notificationid **不正確。 當我更改網址**通知://主機名?id = notificationid ** 其工作正常 –

0

我想你意圖過濾器是不完整的

<!-- To open app using link --> 
    <intent-filter> 
     <action android:name="android.intent.action.VIEW"></action> 
     <category android:name="android.intent.category.DEFAULT"></category> 
     <category android:name="android.intent.category.BROWSABLE"></category> 
     <data android:scheme="http" 
       android:host="yourdomain.com" 
       android:pathPrefix="/someurlparam"> 
     </data> 
    </intent-filter> 
0

第一步:

<intent-filter> 
    <data android:scheme="your_uri_scheme" /> 
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 
</intent-filter> 

第2步:

Uri data = this.getIntent().getData(); 
if (data != null && data.isHierarchical()) { 
    String uri = this.getIntent().getDataString(); 
    Log.i("MyApp", "Deep link clicked " + uri); 
} 
0

添加onNewIntent()方法您Activity,然後使用意向對象,在OnNewintent()方法中是可變的,其具有更新特德方法。

onNewIntent()旨在爲切入點,對於已經在堆棧上運行的其他地方,因此不能稱之爲onCreate()singleTopsingleTask活動。從活動生命週期角度來看,因此需要在onNewIntent()之前致電onPause()。我建議你重寫你的活動,不要在onNewIntent()中使用這些聽衆。例如大部分的時間我onNewIntent()方法僅是這樣的:

@Override 
protected void onNewIntent(Intent intent) { 
    super.onNewIntent(intent); 
//use this intent object to get notificationid for second time 

}