分享意图链接我的应用程序



我仍然是Android开发的新手,我即将向google play商店发布我的第一个应用程序。

我有一个按钮在我的应用程序,这是一个共享按钮。当用户点击它时,我想让它分享我的应用程序的google play链接,但我不知道如何获得我的应用程序的google play链接。

shareBody行,我希望它包含我的应用程序的google play链接。我从这个网站得到了以下代码,所以我真的不明白发生了什么:p

public void ShareClick(View view){
    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    String shareBody = "https://play.google.com/store";
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Download XXXXXX");
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
    startActivity(Intent.createChooser(sharingIntent, "Share via"));
 }

,

String shareBody = "https://play.google.com/store";

我要的是:

String shareBody = "google play link of my app";
谁能告诉我该怎么做?

p。S在我的手机上测试我的应用程序时,每当我进入主菜单或当我按下多任务按钮然后返回我的应用程序时,它都会崩溃

我能做些什么来防止这种情况吗?万分感谢!

使用你的包名而不是链接之类的
market://details?id=" + context.getPackageName()

查看Boss发布的链接,以帮助您了解如何通过Intent启动Play商店。

至于为什么你的应用程序崩溃时,你按home,或多任务处理,这很可能是因为你没有正确处理你的活动生命周期。我假设发生的事情是你的应用程序离开前台,它的状态没有被保存(你没有在onPause()或onStop()中保存某些数据)。当你的应用程序返回到前台时,它会尝试访问不再存在的数据,因为你没有从onStart()或onResume()中检索数据。发布堆栈跟踪,这样我们就可以看到错误,并阅读以下内容:http://developer.android.com/reference/android/app/Activity.html

package com.example.narula.funnysounds;
import android.content.Intent;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends AppCompatActivity {
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    android.support.v7.app.ActionBar actionbar=getSupportActionBar();
    actionbar.hide();
}
@Override
protected void onPause() {
    super.onPause();
    mp.release();
}
private void stopPlaying() {
    if (mp != null) {
        mp.stop();
        mp.release();
        mp = null;
    }
}
public void funnyClick1(View view) {
    stopPlaying();
    mp = MediaPlayer.create(this, R.raw.funny1);
    mp.start();
}
public void funnyClick2(View view){
    stopPlaying();
    mp=MediaPlayer.create(this,R.raw.funny2);
    mp.start();
}
public void funnyClick3(View view) {
    stopPlaying();
    mp= MediaPlayer.create(this, R.raw.funny3);
    mp.start();
}
public void funnyClick4(View view) {
    stopPlaying();
    mp = MediaPlayer.create(this, R.raw.funny4);
    mp.start();
}
public void funnyClick5(View view) {
    stopPlaying();
    mp = MediaPlayer.create(this, R.raw.funny5);
    mp.start();
}
public void funnyClick6(View view) {
    stopPlaying();
    mp = MediaPlayer.create(this, R.raw.funny6);
    mp.start();
}
public void funnyClick7(View view) {
    stopPlaying();
    mp = MediaPlayer.create(this, R.raw.funny7);
    mp.start();
}
public void SuperfunnyClick1(View view){
    stopPlaying();
    mp= MediaPlayer.create(this,R.raw.Sfunny1);
    mp.start();
}
public void Superfunny2(View view){
    stopPlaying();
    mp= MediaPlayer.create(this,R.raw.Sfunny2);
    mp.start();
}
public void ShareClick(View view){
    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    String shareBody = "market://details?id=com.example.narula.funnysounds";
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Download Funny Sounds");
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
    startActivity(Intent.createChooser(sharingIntent, "Share via"));
    }
}

相关内容

最新更新