gpt4 book ai didi

android - 如何在锁屏界面显示未接来电号码?

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:55:03 28 4
gpt4 key购买 nike

我做了一个可以在屏幕锁定时显示未接来电的应用程序,但我不知道如何在锁定屏幕上显示未接来电的数量。通话图像来自 MultiWaveView which已经定义好了,我试过使用OnDraw,用Canvaspaint,绘制指定的坐标。但是它不起作用。所以任何人帮帮我?非常感谢。

image

如何在图片中显示数字(例如图片中的位置2)?

edit1

现在我在应用程序中得到了正确的未接来电数量,但它没有正确显示

类(class):

framework\base\core\java\com\android\internal\widget\multiwaveview\MissedCallView.java

public class MissedCallView extends View {

private static final String TAG = "MissedCallViews";

public static final int UPDATESTART = 10;

private static final int DELAYTIME = 10000;

private int sTempMissedCallCount=-1;

Context mContext;

Canvas mCanvas;

public MissedCallView(Context context)
{

super(context);

Log.i(TAG, "MissedCallView1");

mCanvas=new Canvas();

}

public MissedCallView(Context context, AttributeSet attrs)
{
super(context, attrs);

Log.i(TAG, "MissedCallView2");

mCanvas=new Canvas();

}

public MissedCallView(Context context,int missedCallNum) {

super(context);

sTempMissedCallCount=missedCallNum;

Log.i(TAG, "MissedCallView3");

mCanvas=new Canvas();

}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

if(sTempMissedCallCount>0)

{

Paint paint=new Paint(Paint.ANTIALIASFLAG);
paint.setColor(Color.RED); Log.i(TAG,"Integer.toString(sTempMissedCallCount)is:"+Integer.toString(sTempMissedCallCount)); canvas.drawText(Integer.toString(sTempMissedCallCount),40,310,paint);//50 invalidate();

Log.i(TAG, "invalidate");

}

}

}

这是自定义 View ,只有 MissedCallView(Context context,int missedCallNum) 有效,它在 public class MissCallObserver extends ContentObserver 处调用,当收听未接来电号码时。但是onDraw 不工作,所以应用程序不显示我得到的号码。

编辑 2:

现在我在我的自定义 hanlder 中调用函数,处理程序每​​ 10 秒执行一次

private final Handler mUpdateMissCallNum = new Handler() {
@Override
public void handleMessage(Message msg) {
Log.i(TAG, "mUpdateMissCallNum");
switch (msg.what) {
case UPDATESTART:

Log.i(TAG, "UPDATESTART");
sNewMissedCallCount = getMissedCallCount(mContext);
if (sNewMissedCallCount != sTempMissedCallCount)
{

Log.i(TAG, "sNewMissedCallCount != sTempMissedCallCount");
new Thread(new Runnable()
{
public void run()
{

Log.i(TAG, "sNewMissedCallCount is:"+sNewMissedCallCount);

Log.i(TAG, "sTempMissedCallCount is:"+sTempMissedCallCount);
sTempMissedCallCount = sNewMissedCallCount;
mMissedCallView=new MissedCallView(mContext,sTempMissedCallCount);
//call my costum view here
Log.i(TAG, "sTempMissedCallCount is:"+sTempMissedCallCount);
}
}
).start();
}
break;
default:
break;
}
}
}

我用 canvas 和 paint 绘制它,没有 XML 文件

然后我在 XML:Keyguardscreentabunlock.xml (framework\base\core\res\res\layout) 中锁定屏幕。

在系统中使用Ripple Lock:

<com.android.internal.widget.multiwaveview.MultiWaveView
android:id="@+id/unlockwidget"
android:orientation="horizontal"
android:layoutwidth="matchparent"
android:layoutheight="matchparent"
android:layout_alignParentBottom="true"
android:targetDrawables="@array/lockscreen_targets_with_camera"
android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera"
android:directionDescriptions="@array/lockscreen_direction_descriptions"
android:handleDrawable="@drawable/ic_lockscreen_handle"
android:waveDrawable="@drawable/ic_lockscreen_outerring"
android:outerRadius="@dimen/multiwaveview_target_placement_radius"
android:snapMargin="@dimen/multiwaveview_snap_margin"
android:hitRadius="@dimen/multiwaveview_hit_radius"
android:rightChevronDrawable="@drawable/ic_lockscreen_chevron_right"
android:horizontalOffset="0dip"
android:verticalOffset="60dip"
android:feedbackCount="3"
android:vibrationDuration="20"
/>

然后我明白了:

enter image description here

现在想把未接来电显示在圆心(图片鼠标位置),不知道怎么实现。

最佳答案

你可以使用标志 FLAG_SHOW_WHEN_LOCKED

有关锁定屏幕的更多信息 My android lock

public static final int FLAG_SHOW_WHEN_LOCKED

来自 API 级别 5 的行

Window flag: special flag to let windows be shown when the screen is locked. This will let application windows take precedence over key guard or any other lock screens. Can be used with FLAG_KEEP_SCREEN_ON to turn screen on and display windows directly before showing the key guard window. Can be used with FLAG_DISMISS_KEYGUARD to automatically fully dismisss non-secure keyguards

UPDATE1 未接来电:

您只需要查询电话中的任何电话,然后提取未接来电,然后只需获取查询返回的 Cursor 中的行数

String[] projection = { CallLog.Calls.CACHED_NAME, CallLog.Calls.CACHED_NUMBER_LABEL, CallLog.Calls.TYPE };
String where = CallLog.Calls.TYPE+"="+CallLog.Calls.MISSED_TYPE;
Cursor c = this.getContentResolver().query(CallLog.Calls.CONTENT_URI, selection,where, null, null);
c.moveToFirst();
Log.d("CALL", ""+c.getCount()); //do some other operation
if(c.getCount() == SOME_VALUE_TO_START_APP_ONE)

在 where 子句中,您可以设置数据选择条件。在您的情况下,您需要类型等于 CallLog.Calls.MISSED_TYPE 的所有内容。

您可以选择来电者姓名和他的号码,当然您可以指定要查询的更多信息,例如手机,家庭,工作等号码类型。
该表达式相当于 SQL 查询,类似于:

SELECT CACHED_NAME, CACHED_NUMBER_LABEL, TYPE FROM CONTENT_URI WHERE TYPE=MISSED_TYPE

UPDATE2: how to show the 2 in the picutre .?

您只需在系统设置中设置报警字符串即可,如下:

String message = "2";
Settings.System.putString(context.getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED, message);

关于android - 如何在锁屏界面显示未接来电号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13676595/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com