Translate To Your Own Langauge

Change the Profile Mode Programmatically (Android Example)

Many of the times when we are dealing with Android app development, we need to change the profile mode of our phone as per user's requirement or if you are working with location based app then you need to change the mode according to the location. In this tutorial, i will show you how to change the profile mode of our phone Programmatically

  Follow these simple steps:
1. In the Activity_main.xml file, drag and drop three buttons. If you want to setup an easy UI, just copy and paste the following code into your XML file.

Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/btnSilent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="56dp"
        android:text="Silent" />

    <Button
        android:id="@+id/btnVibe"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btnSilent"
        android:layout_below="@+id/btnSilent"
        android:layout_marginTop="61dp"
        android:text="Viberate" />

    <Button
        android:id="@+id/btnRinger"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/btnVibe"
        android:layout_below="@+id/btnVibe"
        android:layout_marginTop="82dp"
        android:text="Ringer" />

</RelativeLayout>



2. Now you are done with UI, Lets work on the programming part. To do so, copy and paste the following code into mainActivity.java file.

mainActivity.java
package com.example.modeswitcher;

import android.media.AudioManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {
       Button btnSilent, btnVibe, btnRinger;

       @Override
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              final AudioManager mode=(AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
              // Initialization of buttons
              btnSilent = (Button) findViewById(R.id.btnSilent);
              btnVibe = (Button) findViewById(R.id.btnVibe);
              btnRinger = (Button) findViewById(R.id.btnRinger);
              // functionallity of btnSilent
              btnSilent.setOnClickListener(new View.OnClickListener() {

                     @Override
                     public void onClick(View arg0) {
                           // TODO Auto-generated method stub
                           mode.setRingerMode(AudioManager.RINGER_MODE_SILENT);
                           Toast.makeText(getApplicationContext(), "silent mode set", Toast.LENGTH_LONG).show();
                     }
              });

              // functionallity of btnVibe
              btnVibe.setOnClickListener(new View.OnClickListener() {

                     @Override
                     public void onClick(View arg0) {
                           // TODO Auto-generated method stub
                           mode.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
                           Toast.makeText(getApplicationContext(), "Viberate mode set", Toast.LENGTH_LONG).show();
                     }
              });

              // functionallity of btnRinger
              btnRinger.setOnClickListener(new View.OnClickListener() {

                     @Override
                     public void onClick(View arg0) {
                           // TODO Auto-generated method stub
                           mode.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
                           Toast.makeText(getApplicationContext(), "Ringer mode set", Toast.LENGTH_LONG).show();
                     }
              });

       }

       @Override
       public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              getMenuInflater().inflate(R.menu.main, menu);
              return true;
       }

}

by Unknown · 14

Login Example (Android)


In almost every app, we need the user to login into our app so that we can authenticate then to use the required functionality. In this tutorial, i will show you how to make a login page through which we will get username and password of the user. Have a look at the following Steps:

Read more »

by Unknown · 21

Spinner Android Example



Spinner control is sometimes confused with the circular progress bar in Android. Sometimes when it is asked to the fresher about spinner, they generally answer it wrong. Note that Spinner is just like a DropDown. This control is used when we have a lot of entries available but we want user to select only one among them. So here we will try to implement the Spinner into our Android project. Follow these Steps:

Read more »

by Unknown · 17

Showing Map

Now we are done with the basics for implementing the Google Map version 2 (v2) in the Android application. Now one last step of this is how to display the Map in the UI (User Interface). To do so just follow these simple steps given bellow. Before this, make sure that you have successfully generated the SHA1 key and Google API key.

Read more »

by Unknown · 38

Generating Google APIs

Now we are done with Getting the SHA1 key from our computer. If you haven't do this till now, see this tutorial to know how to get SHA1 key. After you successfully generated SHA1 key, now we will learn how to Generate Google APIs for our project. Follow these simple steps:

Read more »

by Unknown · 23

Blogger Widgets
All Rights Reserved Android Tutorials | Designed by: Deepak Anand