你好,我不明白为什么我的聊天头像不显示在屏幕上只有小米设备
除小米MI4外,所有设备都运行良好
这是我的服务
public class CheckInService extends Service {
private int x_init_cord, y_init_cord, x_init_margin, y_init_margin;
private WindowManager windowManager;
private ImageView chatHead;
WindowManager.LayoutParams params;
boolean mHasDoubleClicked = false;
long lastPressTime;
private Boolean _enable = true;
@Override
public void onCreate() {
super.onCreate();
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
Log.e("hiet", ""+height);
chatHead = new ImageView(this);
chatHead.setImageResource(R.drawable.face1);
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
params.x = 10;
params.y = 25;
windowManager.addView(chatHead, params);
/*try {
chatHead.setOnTouchListener(new View.OnTouchListener() {
private WindowManager.LayoutParams paramsF = params;
private int initialX;
private int initialY;
private float initialTouchX;
private float initialTouchY;
@Override public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// Get current time in nano seconds.
long pressTime = System.currentTimeMillis();
// If double click...
if (pressTime - lastPressTime <= 300) {
mHasDoubleClicked = true;
}
else { // If not double click....
mHasDoubleClicked = false;
}
lastPressTime = pressTime;
initialX = paramsF.x;
initialY = paramsF.y;
initialTouchX = event.getRawX();
initialTouchY = event.getRawY();
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
paramsF.x = initialX + (int) (event.getRawX() - initialTouchX);
paramsF.y = initialY + (int) (event.getRawY() - initialTouchY);
windowManager.updateViewLayout(chatHead, paramsF);
break;
}
return false;
}
});
} catch (Exception e) {
// TODO: handle exception
}*/
chatHead.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Log.e("Clickr", "Clickr");
// Intent intent = new Intent(getApplicationContext(), MainActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
// getApplicationContext().startActivity(intent);
}
});
}
private void chathead_click(){
Log.e("Clickr", "Clickr");
}
@Override
public void onDestroy() {
super.onDestroy();
if (chatHead != null)
windowManager.removeView(chatHead);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
try {
} catch (Exception e) {
e.printStackTrace();
}
return super.START_STICKY;
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
}
我在清单文件中添加了
<!-- Check In Service -->
<service android:name=".CheckInService"
android:exported="true">
</service>
你能告诉我为什么小米军情四处不提供服务吗
最佳答案
小米在其安全应用程序下提供了“自动启动”选项。必须手动将此选项切换为“开”。除非完成此操作,否则应用程序将无法执行任何后台任务(如果已终止),并且您将无法执行简单的后台操作,如获取推送通知,更新位置等。此选项使服务能够在后台被终止时重新启动。