2013-05-10 2 views
1

У меня есть приложение, с помощью которого можно отправлять уведомления через GCM. Я получаю уведомление в ящике уведомлений, но когда я нажимаю на него, запускается действие из приложения (EntryActivity). Я бы хотел, чтобы сообщение в уведомлении являлось URL-адресом файла .apk, например «http://path_to_file.apk», после чего я хотел бы, чтобы файл начал загрузку.Android, как начать загрузку apk из ящика уведомлений

Ниже приведен код, генерирующий уведомление, есть ли что-то, что мне нужно добавить или изменить, чтобы начать загрузку?

/** 
    * 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);  

    } 

ответ

0

Попробуйте это:

Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://path_to_file.apk")); 
    notificationIntent.setClassName("com.android.browser", 
           "com.android.browser.BrowserActivity"); 
+0

спасибо, работает отлично. – turtleboy

Смежные вопросы