首先得安装查看smali代码的插件:java2smali
安装完成之后得重启AS,重启之后再build里面有操作选项进行转换操作.
转换完成之后就可以查看转换之后的smali代码了.
转换的java代码如下:
package msl.cc.com.mmmm;
import android.content.Context;
import android.database.ContentObserver;
import android.os.Handler;
public class SMSContentObserver extends ContentObserver {
private static final int MSG_INBOX = 1;
private Context mContext;
private Handler mHandler; // 更新UI线程
public SMSContentObserver(Context mContext,
Handler mHandler) {
super(mHandler); // 所有ContentObserver的派生类都需要调用该构造方法
this.mContext = mContext;
this.mHandler = mHandler;
}
/**
* 当观察到的Uri发生变化时,回调该方法去处理。所有ContentObserver的派生类都需要重载该方法去处理逻辑
* selfChange:回调后,其值一般为false,该参数意义不大
*/
@Override
public void onChange(boolean selfChange) {
// TODO Auto-generated method stub
super.onChange(selfChange);
mHandler.obtainMessage(MSG_INBOX, "SMS Received").sendToTarget();
}
}
转换之后的smali代码如下:
.class public Lmsl/cc/com/mmmm/SMSContentObserver;
.super Landroid/database/ContentObserver;
.source "SMSContentObserver.java"
# static fields
.field private static final MSG_INBOX:I = 0x1
# instance fields
.field private mContext:Landroid/content/Context;
.field private mHandler:Landroid/os/Handler;
# direct methods
.method public constructor <init>(Landroid/content/Context;Landroid/os/Handler;)V
.registers 3
.param p1, "mContext" # Landroid/content/Context;
.param p2, "mHandler" # Landroid/os/Handler;
.prologue
.line 14
invoke-direct {p0, p2}, Landroid/database/ContentObserver;-><init>(Landroid/os/Handler;)V
.line 15
iput-object p1, p0, Lmsl/cc/com/mmmm/SMSContentObserver;->mContext:Landroid/content/Context;
.line 16
iput-object p2, p0, Lmsl/cc/com/mmmm/SMSContentObserver;->mHandler:Landroid/os/Handler;
.line 17
return-void
.end method
# virtual methods
.method public onChange(Z)V
.registers 5
.param p1, "selfChange" # Z
.prologue
.line 26
invoke-super {p0, p1}, Landroid/database/ContentObserver;->onChange(Z)V
.line 27
iget-object v0, p0, Lmsl/cc/com/mmmm/SMSContentObserver;->mHandler:Landroid/os/Handler;
const/4 v1, 0x1
const-string v2, "SMS Received"
invoke-virtual {v0, v1, v2}, Landroid/os/Handler;->obtainMessage(ILjava/lang/Object;)Landroid/os/Message;
move-result-object v0
invoke-virtual {v0}, Landroid/os/Message;->sendToTarget()V
.line 28
return-void
.end method
需要注意的是,工程里面是纯java的话没问题,如果有使用kotlin,中间可能出现报错,报错如下:
Error:Kotlin: Unsupported plugin option:org.jetbrains.kotlin.android:enabled=true
目前没找到解决方式.后续跟踪处理...