通知setContentIntent不起作用

时间:2015-10-27 10:42:06

标签: android android-intent notifications

 new Thread(
            new Runnable() {
                @Override
                public void run() {
                    try {
                        HttpDownloadUtility.downloadFile(url,cookie, mContext, new HttpDownloadUtility.HttpDownloadListener() {
                            @Override
                            public void onProgress(int progress) {
                                Log.d(TAG, "onProgress"+progress);
                                mBuilder.setProgress(100, progress, false);
                                // Displays the progress bar for the first time.
                                mNotifyManager.notify(id, mBuilder.build());
                            }

                            @Override
                            public void onComplete(String file_) {
                                Log.d(TAG, "onComplete");
                                try {

                                    Intent intent = new Intent();
                                     intent.setAction(android.content.Intent.ACTION_VIEW);
                                       File file = new File(file_); 
                                       intent.setDataAndType(Uri.fromFile(file), "application/pdf");

                                    PendingIntent pIntent = PendingIntent.getActivity(MyGapActivity.this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

                                    mBuilder.setContentText("Download complete")
                                            // Removes the progress bar
                                            .setProgress(0, 0, false)
                                            .setSmallIcon(android.R.drawable.stat_sys_download_done)
                                            .setContentIntent(pIntent);
                                    mBuilder.setAutoCancel(true);

                                    mNotifyManager.notify(id, mBuilder.build());
                                }catch (Exception e){
                                    e.printStackTrace();
                                }
                            }

                            @Override
                            public void onStart() {
                                Log.d(TAG, "onStart");
                                mBuilder.setContentTitle("Document Download")
                                        .setContentText("Downloading");
                                mNotifyManager.notify(id, mBuilder.build());

                            }

                            @Override
                            public void onNoFile() {
                                Log.d(TAG, "onNoFile");
                                mBuilder.setContentText("No File to Download")
                                        // Removes the progress bar
                                        .setProgress(0, 0, false);
                                mNotifyManager.notify(id, mBuilder.build());
                            }

                            @Override
                            public void onBegin() {
                                Log.d(TAG, "onBegin");
                                mBuilder.setContentTitle("Document Download")
                                        .setContentText("Connecting to server");
                                mNotifyManager.notify(id, mBuilder.build());
                            }
                        });
                    }catch (Exception  e){
                        e.printStackTrace();
                        mBuilder.setContentText("Download Failed")
                                // Removes the progress bar
                                .setProgress(0, 0, false)
                                .setSmallIcon(android.R.drawable.stat_sys_download_done);
                        mNotifyManager.notify(id, mBuilder.build());
                    }
                }
            }
// Starts the thread by calling the run() method in its Runnable
    ).start();

我正在使用上面的代码从服务器下载文件并显示通知,但是当下载完成后如果我按下通知,则意图没有打开。

如果我使用Thred类有什么问题吗?

许多例子中给出了相同的代码

0 个答案:

没有答案
相关问题