如何的Android开始从通知抽屉里的APK下载 [英] Android how to start an apk download from the notification drawer
本文介绍了如何的Android开始从通知抽屉里的APK下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个应用程序,我可以通过GCM上推送通知。我收到通知抽屉里的通知,但是当我点击它,从应用的活动开始(EntryActivity)。我想发生的情况是,如果在通知中的消息是URL到.apk文件如 HTTP://path_to_file.apk ',然后我想将文件开始下载。
下面是code产生的通知,有什么我需要添加或更改开始下载?
/ **
*问题的通知,通知服务器发送邮件的用户。
* /
私有静态无效generateNotification(上下文的背景下,字符串消息){
INT图标= R.drawable.ic_launcher;
时长= System.currentTimeMillis的();
NotificationManager notificationManager =(NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
通知通知=新的通知(图标,消息,时); 字符串title = context.getString(R.string.app_name);
意图notificationIntent =新意图(背景下,EntryActivity.class); //设置的意图,因此它不会启动新活动
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
的PendingIntent意图=
PendingIntent.getActivity(上下文,0,notificationIntent,0);
notification.setLatestEventInfo(上下文,标题,邮件,意图);
notification.flags | = Notification.FLAG_AUTO_CANCEL; //播放默认通知声音
notification.defaults | = Notification.DEFAULT_SOUND; //如果振动启用震动
notification.defaults | = Notification.DEFAULT_VIBRATE;
notificationManager.notify(0,通知); }
解决方案
试试这个:
意图notificationIntent =新意图(Intent.ACTION_VIEW,Uri.parse(HTTP://path_to_file.apk));
notificationIntent.setClassName(com.android.browser
com.android.browser.BrowserActivity);
I've an app that i can push notifications on to via GCM. I receive the notification in the notification drawer but when i click on it, an activity from the app is started(EntryActivity). What i'd like to happen is if the message in the notification is a url to the .apk file eg 'http://path_to_file.apk', then i'd like the file to start downloading.
Below is the code that generates the notification, is there something i need to add or change to start the download?
/**
* Issues a notification to inform the user that server has sent a message.
*/
private static void generateNotification(Context context, String message) {
int icon = R.drawable.ic_launcher;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
Intent notificationIntent = new Intent(context, EntryActivity.class);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =
PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// Play default notification sound
notification.defaults |= Notification.DEFAULT_SOUND;
// Vibrate if vibrate is enabled
notification.defaults |= Notification.DEFAULT_VIBRATE;
notificationManager.notify(0, notification);
}
解决方案
Try this:
Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://path_to_file.apk"));
notificationIntent.setClassName("com.android.browser",
"com.android.browser.BrowserActivity");
这篇关于如何的Android开始从通知抽屉里的APK下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文