Android Tutorial on launching Default camera, taking picture and set as Device wallpaper | the latest tutorial is now and around Android

Android Tutorial on launching Default camera, taking picture and set as Device wallpaper

Android Tutorial on launching Default camera, taking picture and set as Device wallpaper - Hallo sahabat the latest tutorial is now and around Android, Pada Artikel yang anda baca kali ini dengan judul Android Tutorial on launching Default camera, taking picture and set as Device wallpaper, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan Artikel Android Camera, yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.

Judul : Android Tutorial on launching Default camera, taking picture and set as Device wallpaper
link : Android Tutorial on launching Default camera, taking picture and set as Device wallpaper

Baca juga


Android Tutorial on launching Default camera, taking picture and set as Device wallpaper


Sample Video of How to launch default camera i.e. device camera on one click and take image as well as set as device wallpaper.


Let's make this project.

1. Start a new project and named it 'CameraApp' then click Next.


2. Choose a 'Blank Activity'  and named it 'CameraActivity'. and then finish.


3. In the CameraActivity.java use the below codes

import android.content.Intent;import android.graphics.Bitmap;import android.os.Bundle;import android.provider.MediaStore;import android.support.v7.app.AppCompatActivity;import android.support.v7.widget.Toolbar;import android.view.View;import android.widget.Button;import android.widget.ImageView;import android.widget.Toast;import java.io.IOException;
public class CameraActivity extends AppCompatActivity {

    ImageView 
mImageView;
    Button 
mSetButtonmCameraButton;
    
static final int dataStore 0;
    
protected Bitmap bmp;

    
@Override
    
protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_camera);
        Toolbar toolbar = (Toolbar) findViewById(R.id.
toolbar);
        setSupportActionBar(toolbar);

        initializeVar();

        
mCameraButton.setOnClickListener(new View.OnClickListener() {
            
@Override
            
public void onClick(View v) {
                Intent intent = 
new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, 
dataStore);
            }
        });

        
mSetButton.setOnClickListener(new View.OnClickListener() {
            
@Override
            
public void onClick(View v) {
                
try {
                    getApplicationContext().setWallpaper(
bmp);
                } 
catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    
private void initializeVar() {

        
mCameraButton = (Button) findViewById(R.id.cameraButton);
        
mSetButton = (Button) findViewById(R.id.setButton);
        
mImageView = (ImageView)findViewById(R.id.imageView);
    }

    
@Override
    
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        
super.onActivityResult(requestCode, resultCode, data);

        
if(resultCode == RESULT_OK){

            Bundle extras = data.getExtras();
            
bmp = (Bitmap)extras.get("data");
            
mImageView.setImageBitmap(bmp);
        }
        
else {
            Toast.makeText(CameraActivity.
this"There was an error", Toast.LENGTH_SHORT).show();
        }
    }
}



4. In content_camera.xml file use the below codes...

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
   
xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
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"
   
app:layout_behavior="@string/appbar_scrolling_view_behavior"
   
tools:context="gracious.cameraapp.CameraActivity"
   
tools:showIn="@layout/activity_camera">


    <
ImageView
       
android:layout_width="match_parent"
       
android:layout_height="350dp"
       
android:id="@+id/imageView"
       
android:background="#e9e4ed"
       
android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
       
android:layout_alignParentStart="true"/>

    <
Button
       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
       
android:text="Camera"
       
android:id="@+id/cameraButton" 
        android:layout_alignParentBottom="true"
       
android:layout_centerHorizontal="true" 
        android:layout_marginBottom="106dp"/>

    <
Button
       
android:layout_width="match_parent"
       
android:layout_height="wrap_content"
       
android:text="Set Wallpaper"
       
android:id="@+id/setButton" android:layout_alignParentBottom="true"
       
android:layout_centerHorizontal="true" android:layout_marginBottom="44dp"/>

</
RelativeLayout>


5. To set the device wallpaper you need to include a permission, include the below code in your manifest file.

<uses-permission android:name="android.permission.SET_WALLPAPER"/>
6. Project Layout





Happy Programming :)


For any quires leave the comments below




Demikianlah Artikel Android Tutorial on launching Default camera, taking picture and set as Device wallpaper

Sekianlah artikel Android Tutorial on launching Default camera, taking picture and set as Device wallpaper kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.

Anda sekarang membaca artikel Android Tutorial on launching Default camera, taking picture and set as Device wallpaper dengan alamat link https://kokonghod.blogspot.com/2016/03/android-tutorial-on-launching-default.html

0 Response to "Android Tutorial on launching Default camera, taking picture and set as Device wallpaper"