【问题标题】:How to Open downloaded file on notification click in android?如何在Android中单击通知时打开下载的文件?
【发布时间】:2016-03-02 10:14:37
【问题描述】:

我从 gmail 下载了一个文件。下载完成后,我需要能够单击通知以在我的应用程序中打开下载的文件。 我的文件类型是 csv。

点击上面下载的通过我的app打开的文件,怎么打开?

<activity
            android:label="@string/app_name"
            android:name=".Fakeactivity">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="file" />
                <data android:host="*" />
                <data android:mimeType="text/comma-separated-values" />
                <data android:pathPattern=".*\\.csv" />
            </intent-filter> 
        </activity> 

使用上面的代码通过我的 app.in FakeActivty 打开 csv 文件我已经编写了读取 csv 文件的代码。

【问题讨论】:

    标签: android download mime-types android-notifications


    【解决方案1】:

    你实现了点击通知功能吗 并且您的程序可以处理打开的 csv 文件这里是读取 csv 文件的代码 这是打开活动的代码,它将响应显示 csv 文件

       final Intent intent = new Intent(this, CSVClass.class);
          \\ data you want to send to CSV
        intent.putExtra("key", "value");
        final PendingIntent contentIntent = 
         PendingIntent.getActivity(this,  
          0, intent), 0);
      public class CSVFile {
      InputStream inputStream;
    
      public CSVFile(InputStream inputStream){
        this.inputStream = inputStream;
      }
    
       public List read(){
        List resultList = new ArrayList();
        BufferedReader reader = new BufferedReader(new 
        InputStreamReader(inputStream));
        try {
            String csvLine;
            while ((csvLine = reader.readLine()) != null) {
                String[] row = csvLine.split(",");
                resultList.add(row);
            }
        }
        catch (IOException ex) {
            throw new RuntimeException("Error in reading CSV file: "+ex);
        }
        finally {
            try {
                inputStream.close();
            }
            catch (IOException e) {
                throw new RuntimeException("Error while closing input   
            stream: "+e);
            }
        }
        return resultList;
        }
    
     }
    

    来源http://javapapers.com/android/android-read-csv-file/

    【讨论】:

    • 阅读已在我的活动中完成。但是下载后点击我的文件没有打开。其实我不知道在哪里写通知onclick的功能?
    • 您的问题在于点击通知,因为我知道您需要在代码中创建通知的位置添加 final Intent intent = new Intent(this, MyActivity.class);意图.setData(数据); intent.putExtra("key", "value"); final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent), 0);
    • 如果你想让你的应用程序从下载中打开文件,你需要设置广播接收器告诉操作系统你的程序可以打开.csv文件
    • 如果您希望您的应用程序从下载中打开文件,您需要在您的活动的意图过滤器中进行修改
    猜你喜欢
    • 1970-01-01
    • 2019-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    相关资源
    最近更新 更多