2011-09-27 4 views
3

Je veux que mon application soit ouverte à partir d'un lien, en suivant les instructions de Make a link in the Android browser start up my app?. Eh bien, ça marche bien (la plupart du temps ... c'est la raison pour laquelle je demande de l'aide).Gérer un lien dans le navigateur/Webview Android pour démarrer directement une application

Mon lien html est

<a href="intent:#Intent;action=com.mark.MY_ACTION;end">Open Application</a> 

Mon intention est filtre sous la forme

<intent-filter> 
    <action android:name="com.mark.MY_ACTION"/> 
    <category android:name="android.intent.category.DEFAULT"> 
    <category android:name="android.intent.category.BROWSABLE"> 
</intent-filter> 

So far so good (je l'espère). Cela fonctionne bien de m-o-s-t des navigateurs.

Pour tester ce qui précède, j'ai écrit une activité de démonstration

final WebView webview = new WebView(this); 
setContentView(webview); 
webview.loadUrl("http://www.myhomepage.com/"); 

La page http://www.myhomepage.com/ a des liens personnalisés/HREF (y compris le inent un).

En appuyant sur les liens réguliers me ouvre un navigateur avec ces liens, mais en appuyant sur mon "lien spécial " (le intnet un) ouvre une page 404

page Web non disponible
intention : #Intent; l'action = com.mark.MY_ACTION, fin
pourrait être temporairement ....

Alors que Diane mentionné dans The above link,

Ils vous permettent de diriger le lancement vers votre application sans que l'utilisateur ait la possibilité de se rendre au navigateur ou à toute autre application.

+0

Je crois voici ce que vous cherchez http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser/2958870 # 2958870 – Mars

+1

Ceci est une approche utilisant un schéma, mais comme Diane (mon gourou) a dit "Nous déconseillons fortement aux gens d'utiliser leurs propres régimes, à moins qu'ils ne définissent un nouveau schéma Internet mondial." Je veux utiliser l'intention: .... – Omer

Répondre

1

votre Intent Filter est une même comme mentionné par Diana

<activity android:name=".AntonWorld" 
     android:label="@string/app_name"> 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
    <intent-filter> 
     <data android:scheme="anton" /> 
     <action android:name="android.intent.action.VIEW" /> 
     <category android:name="android.intent.category.BROWSABLE" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
</activity> 

donc la vôtre devrait ressembler:

<intent-filter> 
    <data android:scheme="com.mark.MY_ACTION"/> 
    <category android:name="android.intent.category.DEFAULT"/> 
    <category android:name="android.intent.category.BROWSABLE"/> 
</intent-filter> 

N'a pas tester si android.intent.category.VIEW est nécessaire. Laissez-moi savoir si cela fonctionne.

+0

Diana dit aussi qu'elle avait un problème avec l'ordre des sous-éléments. Peut-être que vous avez besoin de android.intent.category.BROWSEABLE avant android.intent.category.Default. – AliDeo

+0

Je ne veux pas que mon URL soit anton: //www.....com, Je veux transmettre une intention implicite à mon application. – Omer

+0

il ne sera pas anton maintenant que vous avez changé l'intention du filtre suivant subelement: AliDeo

1

Essayez mon truc simple:

 public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      if(url.startsWith("classRegister:")) {     
       Intent MnRegister = new Intent(getApplicationContext(), register.class); startActivity(MnRegister); 
      }    
      view.loadUrl(url); 
      return true; 
     } 

et mon lien html:

<a href="classRegister:true">Go to register.java</a> 

ou vous pouvez faire < a href = "classRegister: vrai"> < - valeur "true" pour le nom de fichier de la classe

cependant ce script fonctionne pour mailto link :)

 if (url.startsWith("mailto:")) { 
      String[] blah_email = url.split(":"); 
      Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
      emailIntent.setType("text/plain"); 
      emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{blah_email[1]}); 
      emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, what_ever_you_want_the_subject_to_be)"); 
      Log.v("NOTICE", "Sending Email to: " + blah_email[1] + " with subject: " + what_ever_you_want_the_subject_to_be); 
      startActivity(emailIntent); 
     } 
1

Ajouter ce code dans Manifest.xml

<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.parag-chauhan.com" 
     android:path="/test" 
     android:scheme="http" /> 
</intent-filter> 

Pour le test créer un autre projet et exécutez le code ci-dessous

Intent i = new Intent(
    Intent.ACTION_VIEW , Uri.parse("http://www.parag-chauhan.com/test") 
); 
startActivity(i); 

Vous pouvez également transmettre paramètre lien. Pour plus d'informations, voir mon blog Make a link in the Android browser start up my app?

Questions connexes