如何通过在Android中单击通知来提供路径(作为字符串)来打开文件?

时间:2019-02-06 06:28:25

标签: java android

我想通过单击通知打开一个特定的文件夹(通过文件管理器存储)。当我单击通知时,我提供的代码没有任何反应,logcat中也没有错误。我应该在当前代码中进行哪些更改?

我已经经历了以下答案,这些似乎都不起作用

Android: How to open a specific folder via Intent and show its content in a file browser?

以下答案不会将我带到所需的文件夹:- https://stackoverflow.com/a/17173655

这是我的代码:-

public void sendNotif(String path)
{
        Uri selectedUri =   Uri.parse(android.os.Environment.getExternalStorageDirectory() + "/" + "App_Ka_Kaam/Electricity/"+pathway+"/");
    Intent intent = new Intent(Intent.ACTION_VIEW,selectedUri);

    intent.setDataAndType(selectedUri, "text/csv");
    intent = Intent.createChooser(intent, "Open folder")
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(electricity_output.this, 0, intent, 0);
    createNotificationChannel();

    Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(electricity_output.this, "1")
            .setSmallIcon(R.drawable.logoo)
            .setContentTitle("File Downloaded")
            .setContentText("Goto your File Manager in " + electricity_output.this.getString(R.string.naam))
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setSound(uri)
            .setContentIntent(pendingIntent)
            .setAutoCancel(true);
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(electricity_output.this);
    notificationManager.notify(0, mBuilder.build());
}

public void createNotificationChannel() {
    // Create the NotificationChannel, but only on API 26+ because
    // the NotificationChannel class is new and not in the support library
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        CharSequence name = "channel";
        String description = "Desc";
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel("1", name, importance);
        channel.setDescription(description);
        // Register the channel with the system; you can't change the importance
        // or other notification behaviors after this
        NotificationManager notificationManager = getSystemService(NotificationManager.class);
        notificationManager.createNotificationChannel(channel);
    }
}

0 个答案:

没有答案