2016-05-31 70 views
1

你好,我是Android开发的新手。我所试图做的是:通过点击通知打开下载目录

  1. 使用URL
  2. 把它放在我的下载
  3. 用于内IntentService一个下载管理器下载
  4. 一旦下载完成下载文件,我显示通知
  5. 通知通知对已下载

用户0

问题是我想让用户点击生成的通知,并打开下载文件夹

我一直在努力为:

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新手,请仔细检查我的错误,以便了解更多信息。 这不是一项任务,我正在自学! 在此先感谢。

+0

也许尝试ACTION_VIEW代替,就像是在这里完成? http://stackoverflow.com/a/34470393/602549 – racs

回答

0

尝试这样

Uri selectedUri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)); 
    Intent intent = new Intent(Intent.ACTION_VIEW); 
    intent.setDataAndType(selectedUri, "resource/folder"); 

    if (intent.resolveActivityInfo(getPackageManager(), 0) != null){ 
      startActivity(intent); 
     } 
     else 
     { 
      // if you reach this place, it means there is no any file 
      // explorer app installed on your device 
     } 

View this thread

+0

什么都没发生 –

+0

虽然点击看到什么是logcat说的? –

+0

也不例外!并且它不打开我的文件夹 –

0

检查这个

public void openFolder() 
{ 
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT); 
    Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()+ "/myFolder/"); 
    intent.setDataAndType(uri, "text/csv"); 
    startActivity(Intent.createChooser(intent, "Open folder")); 
} 
+0

他不是在寻找CVS还是文本文件? –

+0

与此相同的问题 –