将应用名称或文字链接到Google Play市场中的应用链接

时间:2017-01-29 19:01:48

标签: android google-play

我的应用中有一个分享按钮,而不是通过意图http://play.google.com/store/apps/details?id=<package_name>发送应用链接ACTION_SEND我想链接,播放商店中的应用链接到文本(应用名称)。接收器将看到一个名字,然后点击它将重定向到Play商店中的应用程序。我怎么能得到它?

     SpannableString s = new SpannableString("http://play.google.com/store/apps/details?id={packageName}");

                    Linkify.addLinks(s, Linkify.ALL);
                    String messStr = "Check out this event: " + eventObj.getString(Configs.EVENTS_TITLE) + " | from #AppName "+"\n"+s +"\n";
                    Bitmap bitmap = ((BitmapDrawable) eImg.getDrawable()).getBitmap();
                    Uri uri = getImageUri(EventDetails.this, bitmap);
                    Intent intent = new Intent(Intent.ACTION_SEND);
                    intent.setType("image/jpeg");
                    intent.putExtra(Intent.EXTRA_STREAM, uri);
                    intent.putExtra(Intent.EXTRA_TEXT, messStr);
                    startActivity(Intent.createChooser(intent, "Share on..."));

1 个答案:

答案 0 :(得分:1)

更新版本:用户更改包名称

您有按钮,可以将文本设置为您想要的任何内容,然后将onClick方法设置为对play商店的意图

///You need to set an EditText attribute in your layout, similar to how you set the button 
packageName = (EditText) findViewById(R.id.edit); 
Button button = (Button) findViewById(R.id.button_id); 
//locates button from xml layout file

button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
    // Tries to open the play store to your listing 
     String str = packagename.getText().toString();

 try {
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + str)));
    } 
  catch (ActivityNotFoundException e1) 
   { 
//catches error if play store isn't found
        Toast.makeText(this, "Play Store not installed", Toast.LENGTH_SHORT).show();
    }
 } 
 });

这应该在理论上有效。