2014-04-24 17 views
6

Ciao amici sto sviluppando un app, ho avuto un requisito per reindirizzare all'utente di riprodurre negozio da mia app, ho cercato molto, ma senza successo .. codice è sottoRedirect Utente da play store da Android App

Button1.setOnClickListener(new OnClickListener() 
    { 
     @Override 
     public void onClick(View v_arg) { 
      try { 
         Intent viewIntent = 
         new Intent("android.intent.action.VIEW", 
         Uri.parse("https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/")); 
         startActivity(viewIntent); 
      }catch(Exception e) { 
       Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...", 
         Toast.LENGTH_LONG).show(); 
       e.printStackTrace(); 
      } 
     } 
    }); 

    Button2.setOnClickListener(new OnClickListener() 
    { 
     @Override 
     public void onClick(View v_arg) { 
      try { 
         Intent viewIntent = 
         new Intent("android.intent.action.VIEW", 
         Uri.parse("market://details?id=com.adeebhat.rabbitsvilla/")); 
         startActivity(viewIntent); 
      }catch(Exception e) { 
       Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...", 
         Toast.LENGTH_LONG).show(); 
       e.printStackTrace(); 
      } 
     } 
    }); 
+1

Il tuo codice sembra essere ok. Hai avuto qualche errore? –

+0

possibile duplicato di [Come aprire Google Play Store direttamente dalla mia applicazione Android?] (Http://stackoverflow.com/questions/11753000/how-to-open-the-google-play-store-directly-from- my-android-application) – TripeHound

risposta

8

Rimuovi barra dall'URL. Hai aggiunto una barra in più dopo il nome del pacchetto.

https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/ 

Dovrebbe essere

https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla 

Entrambi uri dovrebbe essere

Uri.parse("https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla")); // Removed slash 

e

Uri.parse("market://details?id=com.adeebhat.rabbitsvilla")); // Removed slash 
+0

Grazie mille amici è stato utile –

+0

Il vostro benvenuto :) –

6

Hai solo bisogno di t o rimuovere carattere "/" dall'URL

Quindi sarà

https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla/ 

a

https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla 

Così alla fine

Button1.setOnClickListener(new OnClickListener() 
{ 
    @Override 
    public void onClick(View v_arg) { 
     try { 
        Intent viewIntent = 
        new Intent("android.intent.action.VIEW", 
        Uri.parse("https://play.google.com/store/apps/details?id=com.adeebhat.rabbitsvilla")); 
        startActivity(viewIntent); 
     }catch(Exception e) { 
      Toast.makeText(getApplicationContext(),"Unable to Connect Try Again...", 
        Toast.LENGTH_LONG).show(); 
      e.printStackTrace(); 
     } 
    } 
}); 
+0

Grazie mille amici è stato utile –

+1

siete venuti. – Piyush

11

modo più sofisticato:

final String appPackageName = getPackageName(); // package name of the app 
try { 
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); 
} catch (android.content.ActivityNotFoundException anfe) { 
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName))); 
} 
Problemi correlati