我仍然是Android开发中的新手,我即将将我的第一个应用程序发布到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在我的手机上测试我的应用程序时,每当我进入主菜单或按下多任务按钮然后返回我的应用程序时,它会崩溃
我能做些什么来防止这种情况发生?万分感谢!
答案 0 :(得分:1)
使用您的包名称而不是像这样的链接
void(*function_pointer)(void) = (void (*)(void))function_address;
答案 1 :(得分:0)
检查发布的Boss链接,以帮助您了解如何通过Intent启动Play商店。
至于为什么你的应用程序在你回家或多任务处理时崩溃,很可能是因为你没有正确处理你的Activity Lifecycle。我假设正在发生的事情是您的应用程序离开前台,并且其状态未被保存(您没有在onPause()或onStop()中保存某些数据。当您的应用程序返回到前台时,它会尝试访问数据因为你没有从onStart()或onResume()中检索那些数据,所以不再存在。发布堆栈跟踪以便我们可以看到错误,并阅读: http://developer.android.com/reference/android/app/Activity.html
答案 2 :(得分:0)
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"));
}
}