I have two buttons in my MainActivity, these buttons have OnLongClickListener, and they both start another activity called Pop.class. So everything works fine. What I want is to send a url that correspond to the button in the next activity.
So like this when the user press the button in the MainActivity activity, he is bring by the application on the Pop activity and when clicking on the button in the Pop activity he will be redirected to a YouTube video on the YouTube app that correspond to the url that has been "declared" by the previous button (here b26 or b27).
The problem is that I don't know how to make my string a true URL for the Uri.parse() method. Also I've used a string because I wanted to put different url in each button.
For this I have used putExtra and getExtra but I don't understand why string url is not working whit the b27 button so I didn't modify the b26 code. :(
This is why I'm asking you some help
This is the MainActivity activity :
Button b26 = (Button) findViewById(R.id.b26);
b26.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
if (SoundBuildingOnFiire.isPlaying()) {
SoundBuildingOnFiire.seekTo(0);
} else {SoundBuildingOnFiire.start();}}});
b26.setOnLongClickListener(
new Button.OnLongClickListener() {
public boolean onLongClick(View v) {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);
startActivity(new Intent(MainActivity.this, Pop.class));
return true;}});
Button b27 = (Button) findViewById(R.id.b27);
b27.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v) {
if (SoundJackson.isPlaying()) {
SoundJackson.seekTo(0);
} else {SoundJackson.start();}}});
b27.setOnLongClickListener(
new Button.OnLongClickListener() {
public boolean onLongClick(View v) {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(1000);
startActivity(new Intent(MainActivity.this, Pop.class));
getIntent().putExtra("SoundName", "https://www.youtube.com/");
return true;}});
}
This is the Pop activity :
public class Pop extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popup);
final String SoundName = getIntent().getStringExtra("SoundName");
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int) (width * .8), (int) (height * .4));
TextView txtLabel = (TextView)findViewById(R.id.textView);
txtLabel.setText("En savoir plus sur ce Son");
Button button = (Button)findViewById(R.id.youtube);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent viewIntent =
new Intent("android.intent.action.VIEW",
Uri.parse(SoundName));
startActivity(viewIntent);
}
});
}
}
Thanks for your time