Multiple pages in Eclipse android application - android

i am new in this space i am working with mini app.
i have Animal images in Main template and want when click for example Dog image it must switch another page and there will be dog description and image gallery.
so i need to know how to create multiple pages and redirect it.
this is my app.
Thanks ...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//////////////////////// Dog
Button button3 = (Button)this.findViewById(R.id.button3);
final MediaPlayer dog = MediaPlayer.create(this, R.raw.dog);
button3.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// If the music is playing
if(dog.isPlaying() == true)
// Pause the music player
dog.pause();
// If it's not playing
else
// Resume the music player
dog.start();
}
});

You must create differents activity for different pages.
And use Intent to change page.
Example :
Intent intent = new Intent(MainActivy.this, OtherActivity.class);
startActivity(intent);

Related

Ionic nav-view and external resource

I'm trying to display a video within my application. I've created a link to it such:
Start movie
Everything is fine and the video spins up, but when I push the back button the nav state is resetted and I have to restart my app in order to get back to the "main" page of my app. Is there any trick to maintain the nav state when starting my video?
Yes There is trick you can use the below code in your back button listener
below is the example for your reference you can adjust it by getting the status of your media player like mediaplayer.isPlaying()
final MediaPlayer mp1 = MediaPlayer.create(PlayaudioActivity.this, R.raw.beet);
mBackBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mp1.isPlaying()) {
}else{
finish();
}
}
});

Starting video capture on one click in android

I want to start camera and also to automatically start recording just by clicking an app in android. I have the code to start the camera but I do not know how to start auto capture of the video. Please help.
the code I have for launching camera-
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c1_main);
Intent intent = new Intent("android.media.action.VIDEO_CAPTURE");
StartActivityForResult(intent,CAPTURE_VIDEO_ACTIVITY);
}
I found about view.performclick but do not know how to use for camera
Use MediaRecorder for this purpose. Though it will require more work but will give you much more control. Follow this link http://android-er.blogspot.tw/2011/04/start-video-recording-using.html. Since you don't reuire any button click for recording, keep a delay before starting the camera. Do it like this
myButton.setPressed(true); //you won't click the button
myButton.invalidate();
myButton.postDelayed(new Runnable() {
public void run() {
myButton.setPressed(false);
myButton.invalidate();
releaseCamera(); //release camera from preview before MediaRecorder starts
if(!prepareMediaRecorder()){
Toast.makeText(AndroidVideoCapture.this,"could not prepare MediaRecorder",Toast.LENGTH_LONG).show();
finish();
}
mediaRecorder.start();
}
},5000); //causes delay of 5 seconds befor recording starts
Ok, Make following, changes in your code.
Button play;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c1_main);
play = findViewById ( R.id.btnPlay ); // assuming you have this button in your .xml file.
play.setOnClickListener ( new OnClickListener()
{
#Override
public void onClick ( View view )
{
Intent intent = new Intent("android.media.action.VIDEO_CAPTURE");
StartActivityForResult(intent,CAPTURE_VIDEO_ACTIVITY);
}
});
}

Video Streaming in android using webview

In my application I want to stream video from url. Video is playing perfectly.When user click on that webview its redirect to video's url and showing an alertdialog "Complete action Using" where user can download that video by clicking the option Internet.I want to restrict that means user only watch that video but can not download that. I want user to watch that video using android default player. Thanks in advance.
public class PlayVideo extends Activity {
private String vUrl, vName;
private WebView webView;
Button back, home;
TextView videoName;
Vibrator vibrator;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
// For full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.videoplay);
webView = (WebView) findViewById(R.id.webView01);
back = (Button) findViewById(R.id.bBack);
home = (Button) findViewById(R.id.bHome);
videoName = (TextView) findViewById(R.id.tvVidName);
// for vibration when a button clicked
vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
// getWindow().setFormat(PixelFormat.TRANSLUCENT);
back.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
vibrator.vibrate(40);
finish();
}
});
vName = getIntent().getStringExtra("videoname");
videoName.setText(vName);
vUrl = getIntent().getStringExtra("vid_url");
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setPluginState(WebSettings.PluginState.ON_DEMAND);
webView.getSettings().setJavaScriptEnabled(true);
Log.i("fired url", vUrl);
webView.loadUrl(vUrl);
}
}
You can do that by launching a specific application for streaming the video.
BUT NOTE:
users with only 1 suitable video app, will not see the dialog.
Also,
users that have set a default video app, will not see the dialog
either.
Hence, I would not limit myself, by launching a specific video application, and instead let the android users have a nice android experience.
Should you have very good reasons to launch a specific video player, you can use:
try {
Intent intent = new Intent("com.mxtech.videoplayer.ad"); // Will launch MX player
intent.setDataAndType(Uri.parse("your_path"), "video/*");
startActivity(intent);
} catch(ActivityNotFoundException e){
// the app mxplayer was not found...
Toast.makeText(this, "mx player is not installed", Toast.LENGTH_SHORT).show();
}

Trouble playing mp3 file from raw folder

I wrote my code compiles clean and fine and says no errors. Same code I have used on other apps published on the market. My problem came when I updated the ADT. I read the posts on cleaning it stage by stage, on getting the newest update available, nothing is working for my app. It doesn't play the sound in the raw file. It acts like their is no Raw folder. It compiles without issue but does not play the mp3. Any help would be appreciated.
public class UpdatecodeActivity extends Activity {
MediaPlayer mp1, mp2;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mp1 = MediaPlayer.create(this, R.raw.wait);
mp2 = MediaPlayer.create(this, R.raw.primates);
//Button coding for menu and items
Button btn1 = (Button) findViewById(R.id.btn1);
registerForContextMenu(btn1);
btn1.setOnClickListener(this);
Button btn2 = (Button) findViewById(R.id.btn2);
registerForContextMenu(btn2);
btn2.setOnClickListener(this);
}//Closing tag for OnCreate
//OnClick handler for multiple buttons
public void onClick(View v){
if (v.getId() == R.id.btn1) {
// action to perform on button 1
mp1.start();
} else if (v.getId() == R.id.btn2) {
// action to perform on button 1
mp2.start();
}//Closes Onclick Switches
}//Closes onclick

Android: Video Record using default camera

Below is my code and I'm gonna integrate with the application. My problem is when the button clicked video recorder invoked and video recoded smoothly but I want to get the response from the camera when the video recording is done every time.
public class AndroidVideoActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnVideoRecorder = (Button)findViewById(R.id.buttonClick);
btnVideoRecorder.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent("android.media.action.VIDEO_CAMERA");
startActivity(intent);
}
});
}
}
Can someone please guide me.
Thanks for your time in advance.
Try changing
startActivity(intent);
to
startActivityForResult(intent);
Then when the video is done recordng, it will return to your app and you will be able to do something with the video

Categories

Resources