2016-05-12 79 views
0

如何在android中實現「共享應用程序」功能。我看到很多網站,但都顯示如何共享文件,多媒體等。但沒有適當的代碼共享應用程序本身。誰能幫幫我嗎 ?在Android中共享應用程序功能

回答

4

您可以使用下面的代碼

try 
    { Intent i = new Intent(Intent.ACTION_SEND); 
     i.setType("text/plain"); 
     i.putExtra(Intent.EXTRA_SUBJECT, "My application name"); 
     String sAux = "\nLet me recommend you this application\n\n"; 
     sAux = sAux + "https://play.google.com/store/apps/details?id=Orion.Soft \n\n"; 
     i.putExtra(Intent.EXTRA_TEXT, sAux); 
     startActivity(Intent.createChooser(i, "choose one")); 
    } 
    catch(Exception e) 
    { //e.toString(); 
    } 
+0

更好地利用BuildConfig.APPLICATION_ID,而不是硬編碼。也沒有真正需要這裏的選擇器 – ligi

+0

@克里希納非常感謝 – PersianBlue

0
You can try the below code for sharing your application : 
try { 
      Intent i = new Intent(Intent.ACTION_SEND); 
      i.setType("text/plain"); 
      i.putExtra(Intent.EXTRA_SUBJECT, "Your app name"); 
      String s = "\n Your app recommendation text here\n\n"; 
      s = s + "Your string to mention here(may be playstore url)"; 
      i.putExtra(Intent.EXTRA_TEXT, sAux); 
      mActivity.startActivity(Intent.createChooser(i, "choose to share")); 
     } catch(Exception e) { 
      //e.toString(); 
      e.printStackTrace(); 
     } 
相關問題