嗨我已经实现了我的锁屏幕,当我屏幕上或我的锁屏大便,我可以执行我的任务解锁屏幕现在我的问题是我有一个按钮,在我的锁定屏幕中显示紧急联系人,该按钮显示我存储的联系人我的数据库作为对话或活动。我尝试了很多窗口栏,但是按下我的按钮点击这里是我的锁屏服务
public class LockscreenService extends Service {
private LinearLayout linearLayout;
private WindowManager.LayoutParams layoutParams;
private WindowManager windowManager;
String p;
ImageView img,aimg;
final ArrayList<Bitmap> beforeshuffle = new ArrayList<>(9);
final ArrayList<Bitmap> aftershuffle = new ArrayList<>(9);
ArrayList<Bitmap> smallimages = new ArrayList<Bitmap>(9);
GridView grid;
Bitmap bs;
Bitmap as;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
BroadcastReceiver screenReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF) && linearLayout == null) {
init();
}
}
};
@Override
public void onCreate() {
super.onCreate();
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
registerReceiver(screenReceiver, intentFilter);
windowManager = ((WindowManager) getSystemService(WINDOW_SERVICE));
layoutParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION,
PixelFormat.TRANSLUCENT);
}
private void init() {
linearLayout = new LinearLayout(this);
windowManager.addView(linearLayout, layoutParams);
((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.lockscreen, linearLayout);
// View btnClose = linearLayout.findViewById(R.id.button);
img = (ImageView) linearLayout.findViewById(R.id.bs);
aimg = (ImageView) linearLayout.findViewById(R.id.as);
grid = (GridView) linearLayout.findViewById(R.id.gridView);
Globalvariable c=new Globalvariable();
bs=c.giveBitmap();
String p="/data/user/0/com.example.user.myapplication/app_imageDirrorate/profilerotate.jpg";
Toast.makeText(getApplication(),p,Toast.LENGTH_SHORT).show();
Log.d("path",p);
String bspath="/data/user/0/com.example.user.myapplication/app_Beforeshuffle/beforeshuffle";
bs=loadImageFromStorage(bspath);
// Bitmap bitmap = (Bitmap) i.getParcelableExtra("bitmap");
//smallimage_Numbers is to tell how many smallimage_s the image should split
int smallimage_Numbers = 9;
//Getting the source image to split
// ImageView image = (ImageView) findViewById(R.id.source_image);
// File imgFile = new File("profile.jpg"
Bitmap myBitmap = BitmapFactory.decodeFile(p);
splitImage(myBitmap, smallimage_Numbers);
View btnClose = linearLayout.findViewById(R.id.button8);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
img.setImageBitmap(bs);
as=getBitmapFromView(grid);
aimg.setImageBitmap(as);
Bitmap a=getBitmapFromView(img);
Bitmap b=getBitmapFromView(aimg);
img.setVisibility(View.INVISIBLE);
aimg.setVisibility(View.INVISIBLE);
// do something when the corky3 is clicked
if(b.sameAs(a) ){
// Toast.makeText(getApplicationContext(),"CORRECT",Toast.LENGTH_SHORT).show();
windowManager.removeView(linearLayout);
linearLayout = null;
}
else
{
Log.d("jhgeiugh","jhgfeug");
// Toast.makeText(getApplicationContext(),"WRONG",Toast.LENGTH_SHORT).show();
}
}
});
View btnemergency = linearLayout.findViewById(R.id.button6);
btnemergency.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("ghfgh","dgd");
Intent service = new Intent(LockscreenService.this, PopupService.class);
startService(service);
// Toast.makeText(getApplicationContext(),"setted",Toast.LENGTH_SHORT).show();
}
});
}
这里在btn_emergency我正在试图从另一个SO页面获得的另一个服务popservice
public class PopupService extends Service {
private static final String TAG = PopupService.class.getSimpleName();
WindowManager mWindowManager;
View mView;
EmergencyAdapter emeradap;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("ghfhfd","inpopupservice");
emeradap=new EmergencyAdapter(this);
showDialog(intent.getStringExtra("msg"));
return super.onStartCommand(intent, flags, startId);
}
private void showDialog(String aTitle)
{
PowerManager pm = (PowerManager) getApplicationContext().getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock mWakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "YourServie");
mWakeLock.acquire();
mWakeLock.release();
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mView = View.inflate(getApplicationContext(), R.layout.cononlock, null);
mView.setTag(TAG);
int top = getApplicationContext().getResources().getDisplayMetrics().heightPixels / 2;
LinearLayout dialog = (LinearLayout) mView.findViewById(R.id.ll);
TextView close = (TextView) mView.findViewById(R.id.close);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
hideDialog();
}
});
ListView simple = (ListView) mView.findViewById(R.id.emerlist);
emeradap=new EmergencyAdapter(this);
String[] emercontact=emeradap.fetchUser("vidhya");
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.layout, R.id.tv, emercontact);
simple.setAdapter(arrayAdapter);
final WindowManager.LayoutParams mLayoutParams = new WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, 0, 0,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON ,
PixelFormat.RGBA_8888);
mView.setVisibility(View.VISIBLE);
mWindowManager.addView(mView, mLayoutParams);
mWindowManager.updateViewLayout(mView, mLayoutParams);
}
private void hideDialog(){
if(mView != null && mWindowManager != null){
mWindowManager.removeView(mView);
mView = null;
}
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
但是当我点击按钮时它不会进入弹出服务本身没有任何反应但是在我点击此按钮后锁屏没有任何点击监听器。所有点击都被禁用我不知道为什么。帮我展示我的锁屏概念上的激活或对话。
我的清单中的权限:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>