你好,我无法理解为什么我的聊天图像只显示在小米设备的屏幕上
它在小米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;
}
}
我在Manifest文件中添加了
<!-- Check In Service -->
<service android:name=".CheckInService"
android:exported="true">
</service>
你能告诉我为什么服务不起作用在小米MI4I
答案 0 :(得分:2)
小米在其安全应用程序下提供“自动启动”选项。您必须手动将此选项切换为ON。除非这样做,否则您的应用程序将无法执行任何后台任务,如果它被杀死,您将无法执行简单的后台操作,如获取推送通知,更新位置等。此选项可以重新启动服务以防万一他们在后台被杀。