I want to open a specific folder(in storage via File Manager) by clicking on the notification. When I click on the notification, nothing happens with the code that I've provided, neither there is an error in the logcat. What changes should I make in my current code?
I've gone through following answers already, none of these seem to work
Android: How to open a specific folder via Intent and show its content in a file browser?
The following answer doesn't take me to the required folder:- https://stackoverflow.com/a/17173655
Here is my code:-
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);
}
}