欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android設(shè)置默認鎖屏壁紙接口的方法

 更新時間:2022年01月06日 12:11:57   作者:lancelots  
這篇文章主要介紹了Android默認鎖屏壁紙接口的設(shè)置方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Android設(shè)置默認鎖屏壁紙接口的具體代碼,供大家參考,具體內(nèi)容如下

完成自定義service后,接下來就是具體實現(xiàn)接口

1、在frameworks/base/core/java/android/app/customized/ICustomizedService.aidl中定義接口

boolean setLockScreenWallpaper(String uri);

2、在frameworks/base/core/java/android/app/customized/CustomizedManager.java中實現(xiàn)接口

package android.app.customized;
?
import android.util.Log;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.RemoteException;
import android.provider.Settings;
import java.io.IOException;
import android.os.ServiceManager;
import android.os.IBinder;
import java.util.List;
import android.app.ActivityManager;
import android.graphics.Bitmap;
?
?
public class CustomizedManager{
? ? private static final String TAG="CustomizedManager";
? ? private static final boolean DBG=true;
? ??
? ? private static ICustomizedService mService;
? ? private final Context mContext;
?
?
? ? public CustomizedManager(Context context){
? ? ? ? mContext = context;
? ? ? ? mService = ICustomizedService.Stub.asInterface(
? ? ? ? ? ? ? ? ServiceManager.getService("customized"));
? ? }
? ? private static ICustomizedService getService(){
? ? ? ? if (mService != null) {
? ? ? ? ? ? return mService;
? ? ? ? }
? ? ? ??
? ? ? ? IBinder b = ServiceManager.getService("customized"
? ? ? ? mService = ICustomizedService.Stub.asInterface(b);
? ? ? ? return mService;
? ? }
?
? ?public boolean setLockScreenWallpaper(String uri) {
? ? ? ? try {
? ? ? ? ? ? getService().setLockScreenWallpaper(uri);
? ? ? ? } catch (RemoteException e) {
? ? ? ? }
? ? ? ? return false;
? ? }
?
}

3、在frameworks/base/services/core/java/com/android/server/customized/CustomizedService.java中對AIDL文件中定義的接口進行具體實現(xiàn).

package com.android.server.customized;
?
import android.os.IBinder;
import android.os.ServiceManager;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.app.customized.ICustomizedService;
import android.content.BroadcastReceiver;
import android.view.IWindowManager;
import android.view.WindowManagerGlobal;
import android.graphics.BitmapFactory;
?
?
public class CustomizedService extends ICustomizedService.Stub {
? ? private static final String TAG = "CustomizedService ";
? ? private Context mContext;
?
? ? public static class Lifecycle extends SystemService {
? ? ? ? private CustomizedService mService;
?
? ? ? ?public Lifecycle(Context context) {
? ? ? ? ? ? super(context);
? ? ? ? }
?
? ? ? ? @Override
? ? ? ? public void onStart() {
? ? ? ? ? ? mService = new CustomizedService (getContext());
? ? ? ? ? ? publishBinderService(Context.CUSTOMIZED, mService);
? ? ? ? }
?
? ? ? ?@Override
? ? ? ? public void onBootPhase(int phase) {
? ? ? ? }
?
? ? ? ? @Override
? ? ? ? public void onUnlockUser(int userHandle) {
? ? ? ? }
? ? }
?
? ? public CustomizedService (Context context) {
? ? ? ?mContext = context;
? ?}
?
? ? public boolean setLockScreenWallpaper(String uri) {
? ? ? ? if (uri == null || "".equals(uri))
? ? ? ? ? ? return false;
? ? ? ? File file = new File(uri);
? ? ? ? if (!file.exists()) {
? ? ? ? ? ? return false;
? ? ? ? }
? ? ? ? Log.d(TAG, "setLockScreenWallpaper uri===============" + uri);
? ? ? ? long ident = Binder.clearCallingIdentity();
? ? ? ? Intent sendlock = new Intent();
? ? ? ? String packageName = "com.android.launcher3";
? ? ? ? String serviceClassName = packageName + ".LockScreenWallPaperService";
? ? ? ? sendlock.putExtra("path", uri);
? ? ? ? sendlock.setComponent(new ComponentName(packageName, serviceClassName));
? ? ? ? mContext.startServiceAsUser(sendlock, UserHandle.OWNER);
? ? ? ? Binder.restoreCallingIdentity(ident);
? ? ? ? return true;
? ? }
?
?
}

4、在packages/apps/Launcher3/AndroidManifest.xml中注冊LockScreenWallPaperService

<service
? ? ? ? ? ? android:name="com.android.launcher3.LockScreenWallPaperService"
? ? ? ? ? ? android:exported="true" >
? ? ? ? ? ? <intent-filter>
? ? ? ? ? ? ? ? <action android:name="com.android.launcher.action.SET_LOCKSCREENWALLPAPER_SERVICE" />
? ? ? ? ? ? </intent-filter>
</service>

5、因為我們只是在CustomizedService 中調(diào)用setLockScreenWallpaper方法啟動LockScreenWallPaperService,所以設(shè)置默認wallpaper還是要由setLockScreenWallpaper實現(xiàn)的.下面要實現(xiàn)LockScreenWallPaperService了,路徑為packages/apps/Launcher3/src/com/android/launcher3/LockScreenWallPaperService.java

package com.android.launcher3;
?
import android.app.Service;
import android.os.*;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.content.Context;
import android.content.Intent;
import android.graphics.Matrix;
import android.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
?
public class LockScreenWallPaperService extends Service {
? ? private String TAG = "LockScreenWallPaperService";
? ? private String path = "";
?
? ? @Override
? ? public void onCreate() {
?
? ? }
?
? ? @Override
? ? public int onStartCommand(Intent intent, int flags, int startId) {
? ? ? ? Log.d(TAG, "onStartCommand ");
?
? ? ? ? if (intent != null) {
? ? ? ? ? ? path = intent.getStringExtra("path");
? ? ? ? }
?
? ? ? ? Bitmap bitmap = BitmapFactory.decodeFile(path);
? ? ? ? SavePicToLocal savePic = new SavePicToLocal(bitmap);
? ? ? ? savePic.execute("save picture");
?
? ? ? ? return START_STICKY;
? ? }
?
? ? public boolean dumpBitmap(Bitmap mBitmap) throws FileNotFoundException {
? ? ? ? Log.d(TAG, "dumpBitmap");
? ? ? ? boolean flagSaveCompelete = false;
? ? ? ? Bitmap bitmap_land, bitmap_port;
? ? ? ? int height = mBitmap.getHeight();
? ? ? ? int width = mBitmap.getWidth();
?
? ? ? ? int lswidth = 1920;
? ? ? ? int lsheight = 1200;
? ? ? ? float lper = Math.max((float) lswidth / (float) width, (float) lsheight
? ? ? ? ? ? ? ? / (float) height);
? ? ? ? if (lper > 1) {
? ? ? ? ? ? Matrix lmatrix = new Matrix();
? ? ? ? ? ? lmatrix.postScale(lper, lper);
? ? ? ? ? ? bitmap_land = Bitmap.createBitmap(mBitmap,
? ? ? ? ? ? ? ? ? ? (int) ((mBitmap.getWidth() - lswidth / lper) / 2),
? ? ? ? ? ? ? ? ? ? (int) ((mBitmap.getHeight() - lsheight / lper) / 2),
? ? ? ? ? ? ? ? ? ? (int) (lswidth / lper), (int) (lsheight / lper), lmatrix,
? ? ? ? ? ? ? ? ? ? true);
? ? ? ? } else {
? ? ? ? ? ? bitmap_land = Bitmap.createBitmap(mBitmap,
? ? ? ? ? ? ? ? ? ? (int) ((mBitmap.getWidth() - lswidth) / 2),
? ? ? ? ? ? ? ? ? ? (int) ((mBitmap.getHeight() - lsheight) / 2), lswidth,
? ? ? ? ? ? ? ? ? ? lsheight, null, true);
? ? ? ? }
?
? ? ? ? int pswidth = 1200;
? ? ? ? int psheight = 1920;
? ? ? ? float pper = Math.max((float) pswidth / (float) width, (float) psheight
? ? ? ? ? ? ? ? / (float) height);
? ? ? ? if (pper > 1) {
? ? ? ? ? ? Matrix pmatrix = new Matrix();
? ? ? ? ? ? pmatrix.postScale(pper, pper);
? ? ? ? ? ? bitmap_port = Bitmap.createBitmap(mBitmap,
? ? ? ? ? ? ? ? ? ? (int) ((mBitmap.getWidth() - pswidth / pper) / 2),
? ? ? ? ? ? ? ? ? ? (int) ((mBitmap.getHeight() - psheight / pper) / 2),
? ? ? ? ? ? ? ? ? ? (int) (pswidth / pper), (int) (psheight / pper), pmatrix,
? ? ? ? ? ? ? ? ? ? true);
? ? ? ? } else {
? ? ? ? ? ? bitmap_port = Bitmap.createBitmap(mBitmap,
? ? ? ? ? ? ? ? ? ? (int) ((mBitmap.getWidth() - pswidth) / 2),
? ? ? ? ? ? ? ? ? ? (int) ((mBitmap.getHeight() - psheight) / 2), pswidth,
? ? ? ? ? ? ? ? ? ? psheight, null, true);
? ? ? ? }
? ? ? ? Matrix matrix = new Matrix();
? ? ? ? matrix.postScale(0.5f, 0.5f);
? ? ? ? bitmap_land = Bitmap.createBitmap(bitmap_land, 0, 0,
? ? ? ? ? ? ? ? bitmap_land.getWidth(), bitmap_land.getHeight(), matrix, true);
? ? ? ? bitmap_port = Bitmap.createBitmap(bitmap_port, 0, 0,
? ? ? ? ? ? ? ? bitmap_port.getWidth(), bitmap_port.getHeight(), matrix, true);
? ? ? ? flagSaveCompelete = saveBitmapToFile(
? ? ? ? ? ? ? ? bitmap_port,
? ? ? ? ? ? ? ? "/data/local/tmp/lockscreenwallpaper/keyguard_wallpaper_land.png",
? ? ? ? ? ? ? ? 1);
? ? ? ? flagSaveCompelete = saveBitmapToFile(
? ? ? ? ? ? ? ? bitmap_land,
? ? ? ? ? ? ? ? "/data/local/tmp/lockscreenwallpaper/keyguard_wallpaper_port.png",
? ? ? ? ? ? ? ? 2);
? ? ? ? return flagSaveCompelete;
? ? }
?
? ? private boolean saveBitmapToFile(Bitmap bitmap, String path, int isRecycle)
? ? ? ? ? ? throws FileNotFoundException {
?
? ? ? ? Log.d(TAG, "saveBitmapToFile ident=" + "bitmap" + bitmap);
? ? ? ? boolean result = false;
? ? ? ? if (bitmap == null)
? ? ? ? ? ? return result;
? ? ? ? Bitmap tmpbm = null;
? ? ? ? java.io.FileOutputStream tmpfos = null;
? ? ? ? try {
? ? ? ? ? ? tmpbm = bitmap;
? ? ? ? ? ? tmpfos = new java.io.FileOutputStream(path);
? ? ? ? ? ? tmpbm.compress(Bitmap.CompressFormat.PNG, 100, tmpfos);
? ? ? ? ? ? Log.d(TAG, "saveBitmapToFile compress");
? ? ? ? } catch (FileNotFoundException ex) {
? ? ? ? ? ? Log.d(TAG, "ex1" + ex);
? ? ? ? ? ? throw ex;
? ? ? ? } catch (java.io.IOException ex) {
? ? ? ? ? ? Log.d(TAG, "ex2" + ex);
? ? ? ? ? ? ex.printStackTrace();
? ? ? ? } finally {
? ? ? ? ? ? if (tmpfos != null) {
? ? ? ? ? ? ? ? try {
? ? ? ? ? ? ? ? ? ? Log.d(TAG, "tmpfos.close() ");
? ? ? ? ? ? ? ? ? ? tmpfos.close();
? ? ? ? ? ? ? ? ? ? result = true;
? ? ? ? ? ? ? ? } catch (java.io.IOException ex) {
? ? ? ? ? ? ? ? ? ? Log.d(TAG, "ex3" + ex);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? if (tmpbm != null && !tmpbm.isRecycled())
? ? ? ? ? ? ? ? if (isRecycle == 2) {
? ? ? ? ? ? ? ? ? ? tmpbm.recycle();
? ? ? ? ? ? ? ? }
? ? ? ? }
?
? ? ? ? return result;
? ? }
?
? ? class SavePicToLocal extends AsyncTask<String, Integer, Boolean> {
? ? ? ? Bitmap bitmap;
? ? ? ??
? ? ? ? public SavePicToLocal(Bitmap mBitmap) {
? ? ? ? ? ? bitmap = mBitmap;
? ? ? ? }
?
? ? ? ? @Override
? ? ? ? protected Boolean doInBackground(String... params) {
? ? ? ? ? ? return dumpBitmaps();
? ? ? ? }
?
? ? ? ? private boolean dumpBitmaps() {
? ? ? ? ? ? boolean flag = false;
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? flag = dumpBitmap(bitmap);
? ? ? ? ? ? ? ? flag = true;
? ? ? ? ? ? } catch (FileNotFoundException e) {
? ? ? ? ? ? }
? ? ? ? ? ? return flag;
? ? ? ? }
? ? ? ? @Override
? ? ? ? protected void onPostExecute(Boolean result) {
? ? ? ? ? ? if (result) {
? ? ? ? ? ? ? ? sendBroadcast(new Intent(
? ? ? ? ? ? ? ? ? ? ? ? "android.intent.action.UPDATE_LOCK_WALLPAPER"));
? ? ? ? ? ? ? ? Log.d(TAG, "send UPDATE_LOCK_WALLPAPER");
? ? ? ? ? ? }
?
? ? ? ? }
?
? ? ? ? @Override
? ? ? ? protected void onProgressUpdate(Integer... values) {
? ? ? ? ? ? super.onProgressUpdate(values);
? ? ? ? }
? ? }
?
? ? @Override
? ? public IBinder onBind(Intent intent) {
? ? ? ? return null;
? ? }
?
}

然后編譯一下,就可以通過接口設(shè)置默認桌面了,大功告成。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • android IPC之binder通信機制

    android IPC之binder通信機制

    Binder通信機制說來簡單,但是在使用的過程的遇到了一些問題,最后終于解決了,現(xiàn)在曬出來和大家分享一下,希望可以幫助你們
    2012-11-11
  • Android源碼使用16進制進行狀態(tài)管理的方法

    Android源碼使用16進制進行狀態(tài)管理的方法

    這篇文章主要介紹了Android源碼使用16進制進行狀態(tài)管理的方法,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-07-07
  • Android輪播圖點擊圖片放大效果的實現(xiàn)方法

    Android輪播圖點擊圖片放大效果的實現(xiàn)方法

    這篇文章主要給大家介紹了關(guān)于Android輪播圖點擊圖片放大效果的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-08-08
  • android 實現(xiàn)APP中改變頭像圖片的實例代碼

    android 實現(xiàn)APP中改變頭像圖片的實例代碼

    這篇文章主要介紹了android 實現(xiàn)APP中改變頭像圖片的實例代碼,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-07-07
  • Android FFmpeg音視頻解碼播放示例詳解

    Android FFmpeg音視頻解碼播放示例詳解

    這篇文章主要為大家介紹了Android FFmpeg音視頻解碼播放示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-10-10
  • Android表格自定義控件使用詳解

    Android表格自定義控件使用詳解

    這篇文章主要為大家詳細介紹了Android表格自定義控件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Android繪制儀表盤指針刻度

    Android繪制儀表盤指針刻度

    這篇文章主要為大家詳細介紹了Android繪制儀表盤指針刻度,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Android三種方式生成矢量圖之VectorDrawable類使用詳解

    Android三種方式生成矢量圖之VectorDrawable類使用詳解

    這篇文章主要介紹了Android三種方式生成矢量圖的VectorDrawable類,2014年6月26日的I/O?2014開發(fā)者大會上谷歌正式推出了Android?L,它帶來了全新的設(shè)計語言Material?Design,新的API也提供了這個類VectorDrawable
    2023-02-02
  • Android?拍照后返回縮略圖的兩種方法介紹

    Android?拍照后返回縮略圖的兩種方法介紹

    大家好,本篇文章主要講的是Android?拍照后返回縮略圖的兩種方法介紹,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-01-01
  • Android開發(fā)之App widget用法實例分析

    Android開發(fā)之App widget用法實例分析

    這篇文章主要介紹了Android開發(fā)之App widget用法,結(jié)合實例形式詳細分析了Android開發(fā)中使用App widget組件的具體步驟與相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2016-06-06

最新評論