2012-07-24 112 views
0

我的代码显示通知栏,当我点击它开始下载。唯一的问题是它到了浏览器并从那里开始。我希望下载开始,但它不会去浏览器。我的代码是:“我不在乎这是怎么打开的,所以使用默认的行为”开始下载通知栏点击android

Intent NotifyIntent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse(ApkFileLocation)); 

       PendingIntent intent = PendingIntent.getActivity(EnquireActivity.this, 0, NotifyIntent, 0); 
       NotificationDetails.setLatestEventInfo(context, ContentTitle, ContentText, intent); 

       mNotificationManager.notify(SIMPLE_NOTFICATION_ID, NotificationDetails); 

回答

0

通过与URL设置NotifyIntentandroid.content.Intent.ACTION_VIEW,你是在告诉系统,

如果您希望下载发生在后台,您应该实施Service并编写代码以在该处下载文件。然后让NotifyIntent指向BroadcastReceiver,它将启动Service。该服务应该能够将通知栏中的下载状态显示为“正在进行”的活动(不能被解雇)。

编辑:看起来你可以以这种方式使用的意图直接启动服务:

Intent NotifyIntent = new Intent(context, MyService.class); 
PendingIntent intent = PendingIntent.getService(context, 0, NotifyIntent, 0); 
+0

感谢@mtmurdock什么我应该写,而不是android.content.Intent.ACTION_VIEW? – 2012-07-24 15:03:23

+0

更新了解答更多答案。 – mtmurdock 2012-07-24 15:08:03

+0

让我清楚我到底在找什么。我已经把apk文件。所以每当有新的更新通知出现时,就会出现。然后点击通知,它应该开始下载新的更新。我做错了什么? – 2012-07-24 15:16:32