【发布时间】:2016-05-31 04:40:17
【问题描述】:
您好,我是 Android 开发的新手。我想做的是:
- 使用 URL 下载文件
- 放在我的下载中
- 使用 IntentService 中的下载管理器进行下载
- 下载完成后,我会显示一个通知
- 通知通知用户下载完成
问题是我希望用户点击生成的通知,然后打开下载文件夹!
我一直在尝试的是:
public void sendNotification() {
// Use NotificationCompat.Builder to set up our notification.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
//icon appears in device notification bar and right hand corner of notification
builder.setSmallIcon(R.drawable.downloaded);
// This intent is fired when notification is clicked
*****Here I want the user if clicks this notification the Download Folder should Open up*****
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri imgUri = Uri.fromFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS));
intent.setDataAndType(imgUri, "file/*");
startActivity(intent);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
// Set the intent that will fire when the user taps the notification.
builder.setContentIntent(pendingIntent);
// Large icon appears on the left of the notification
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.downloaded));
// Content title, which appears in large type at the top of the notification
builder.setContentTitle("Complete");
// Content text, which appears in smaller text below the title
builder.setContentText("Your Download has been completed Successfully!");
//set the subtext
builder.setSubText("Click to open the Downloads Folder!");
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Will display the notification in the notification bar
notificationManager.notify(NOTIFICATION_ID, builder.build());
}
当我点击它时,什么也没发生!
我是 Android 新手,请检查我的错误,以便我了解更多信息。 这不是作业,我正在自学! 提前致谢。
【问题讨论】:
-
也许试试 ACTION_VIEW ,就像这里做的一样? stackoverflow.com/a/34470393/602549
-
你找到解决办法了吗?
-
@Andriod Nerd - 请告诉您解决方案了吗?
标签: android android-intent android-notifications