how to show the missed call number in lock screen?
android, screen-lock
Solution
you can make use of flag `FLAG_SHOW_WHEN_LOCKED`
for more information on lock screen My android lock
public static final int FLAG_SHOW_WHEN_LOCKED
Lines from API level 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 for missed calls:
All you need is to query the phone for any calls then extract missed one & Then just get the count of rows in the Cursor that is return by the query
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)
In the where clause you set condition for selection of data. In your case you need everything which type equals `CallLog.Calls.MISSED_TYPE`.
you can select the Name of the caller and his number, ofcourse you can specify more information to be queried like type of number like mobile, home, work. The expression is equivalent to SQL query, something like:
SELECT CACHED_NAME, CACHED_NUMBER_LABEL, TYPE FROM CONTENT_URI WHERE TYPE=MISSED_TYPE
UPDATE2: how to show the 2 in the picutre .?
All you need to do is set the alarm string in the system settings, as follows:
String message = "2";
Settings.System.putString(context.getContentResolver(),
Settings.System.NEXT_ALARM_FORMATTED, message);
Problem
I have make an app that can show missed call when screen is locked,but I don't know how to show number of missed call on the locked screen.the call image is from `MultiWaveView`which has defined already,I have trid using `OnDraw`,with `Canvas` and `paint`,draw the specify coordinate.but it doesn't work .so anyone help me?thanks a lot. how to show the number(e.g.in picture is position 2 )in the picutre? edit1 for now I have get the right number of missed call in app,but it doesn't show correctly 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"); } } ``` } this is the custom view ,Only `MissedCallView(Context context,int missedCallNum)` works ,it called at `public class MissCallObserver extends ContentObserver` when listen the missed called number .but the onDraw doesn't work ,so the app doesn't show the number I have got. EDIT2: for now I call the function in my custom hanlder, handler do every 10 second ``` 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; } } } ``` I draw it with canvas and paint,without XML files then I lock screen in XML:Keyguardscreentabunlock.xml (framework\base\core\res\res\layout). which is use Ripple Lock in system: ``` <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" /> ``` then I get this : Now I want to show the missed call number on the center of the circle(in the picuture mouse position.),And I don't know how to achieve.