This repository was archived by the owner on Feb 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 206
This repository was archived by the owner on Feb 3, 2020. It is now read-only.
getDisplayCutout() on a null object reference #110
Copy link
Copy link
Closed
Description
Hello i am getting this error:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.DisplayCutout android.view.WindowInsets.getDisplayCutout()' on a null object reference
at jp.co.recruit_lifestyle.android.floatingview.FloatingViewManager.findCutoutSafeArea(FloatingViewManager.java:618)
I am starting a service like this:
intent.putExtra(GraphHeadService.EXTRA_CUTOUT_SAFE_AREA, FloatingViewManager.findCutoutSafeArea(this));
ContextCompat.startForegroundService(this, intent);
Is there any problem with FloatingViewManager.findCutoutSafeArea(this)?
My GraphHeadService.java
package in.graphhed.app;
import android.app.Notification;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.os.IBinder;
import android.support.v4.app.NotificationCompat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import jp.co.recruit_lifestyle.android.floatingview.FloatingViewListener;
import jp.co.recruit_lifestyle.android.floatingview.FloatingViewManager;
public class GraphHeadService extends Service implements FloatingViewListener {
private FloatingViewManager mFloatingViewManager;
private static final String TAG = "GraphHeadService";
private static final int NOTIFICATION_ID = 5469;
public static final String EXTRA_CUTOUT_SAFE_AREA = "cutout_safe_area";
public GraphHeadService() {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (mFloatingViewManager != null) {
return START_STICKY;
}
final DisplayMetrics metrics = new DisplayMetrics();
final WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(metrics);
final LayoutInflater inflater = LayoutInflater.from(this);
final ImageView iconView = (ImageView) inflater.inflate(R.layout.layout_floating_widget, null, false);
iconView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "Chathead Clicked");
}
});
mFloatingViewManager = new FloatingViewManager(this, this);
mFloatingViewManager.setFixedTrashIconImage(R.drawable.ic_trash_fixed);
mFloatingViewManager.setActionTrashIconImage(R.drawable.ic_trash_action);
mFloatingViewManager.setSafeInsetRect((Rect) intent.getParcelableExtra(EXTRA_CUTOUT_SAFE_AREA));
final FloatingViewManager.Options options = new FloatingViewManager.Options();
options.overMargin = (int) (16 * metrics.density);
mFloatingViewManager.addViewToWindow(iconView, options);
startForeground(NOTIFICATION_ID, createNotification(this));
return START_REDELIVER_INTENT;
}
@Override
public void onDestroy() {
destroy();
super.onDestroy();
}
public void onFinishFloatingView() {
stopSelf();
}
@Override
public void onTouchFinished(boolean isFinishing, int x, int y) {
if (isFinishing) {
Log.d(TAG, "Deleting Soon");
} else {
Log.d(TAG, "Deleted "+ getString(x, y));
}
}
private void destroy() {
if (mFloatingViewManager != null) {
mFloatingViewManager.removeAllViewToWindow();
mFloatingViewManager = null;
}
}
private static Notification createNotification(Context context) {
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context, context.getString(R.string.default_floatingview_channel_id));
builder.setWhen(System.currentTimeMillis());
builder.setSmallIcon(R.mipmap.ic_launcher);
builder.setContentTitle("Title");
builder.setContentText("Content");
builder.setOngoing(true);
builder.setPriority(NotificationCompat.PRIORITY_MIN);
builder.setCategory(NotificationCompat.CATEGORY_SERVICE);
return builder.build();
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}
and my DataReceiverActivity.java
package in.graphhed.app;
import android.content.Intent;
import android.os.Build;
import android.provider.Settings;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;
import jp.co.recruit_lifestyle.android.floatingview.FloatingViewManager;
public class DataReceiverActivity extends AppCompatActivity {
private TextView intentEcho;
private static final int SYSTEM_ALERT_WINDOW_PERMISSION = 5469;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_data_receiver);
Intent receivedIntent = getIntent();
String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
Toast.makeText(this, "In App Viewer!", Toast.LENGTH_SHORT).show();
} else if (Settings.canDrawOverlays(this)) {
Intent intent = new Intent(this, GraphHeadService.class);
//intent.putExtra("url", receivedText);
intent.putExtra(GraphHeadService.EXTRA_CUTOUT_SAFE_AREA, FloatingViewManager.findCutoutSafeArea(this));
ContextCompat.startForegroundService(this, intent);
this.moveTaskToBack(true);
finish();
} else {
Toast.makeText(this, "In App Viewer!", Toast.LENGTH_SHORT).show();
}
}
}
Metadata
Metadata
Assignees
Labels
No labels