Notfication启动意图而不点击,并且没有显示在顶部

时间:2018-01-30 18:35:27

标签: android android-studio notifications

这是我的通知代码:

private void DrawNotfication(Context context) {

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        File xlsx = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "test.xlsx");
        Uri path = Uri.fromFile(xlsx);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(path, "application/vnd.ms-excel");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        try {
            context.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Toast.makeText(context, "No Application available to view XLS", Toast.LENGTH_SHORT).show();
        }

        PendingIntent ped = PendingIntent.getActivity(this, 0, intent, 0);

        Notification notification = new Notification.Builder(this).setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("title")
                .setContentText("content")
                .setAutoCancel(true)
                .setPriority(Notification.PRIORITY_MAX)
                .setContentIntent(ped)
                .build();
        mNotificationManager.notify(0, notification);

}

出于某种原因,当它显示通知时,它会在我点击之前启动意图..而且它也不会出现在屏幕顶部..

我该如何解决?

谢谢!

0 个答案:

没有答案