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
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 mSetButton, mCameraButton; 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(); } } } |
<?xml version="1.0" encoding="utf-8"?> android:layout_alignParentLeft="true" android:layout_alignParentBottom="true" android:layout_marginBottom="106dp"/> |
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"
Post a Comment