2013-05-31 38 views
0

我有一个使用GCM推送通知的应用程序。当我向我测试的手机(HTC Desire C,三星mini等)推送通知时,它可以正常工作。该通知是修复了错误的应用程序的网址。BrowserActivity泄漏了窗口

通常会发生的是收到推送,一旦点击浏览器打开并下载开始。下载完成后,用户可以点击通知画面中的通知和应用程序安装/升级。

问题是,当我试图在摩托罗拉藐视迷你XT320上运行这个。它可以接收推送,但浏览器在关闭之前第一次打开并且下载未启动。

有没有人有任何想法为什么?以下是我如何生成通知以及错误。浏览器打开时,我可以看到一秒钟弹出一个对话框。我知道这个错误可能与此有关,因为它是一个泄漏的窗口错误。我不创建这个对话框,它是Android浏览器活动的一部分。

在此先感谢。

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); 
     Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(message)); 


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

    } 

05-31 15:39:01.940: V/InputMethodManager(1310): focusOut: [email protected] [email protected] winFocus=false 
05-31 15:39:02.170: V/InputMethodManager(1310): focusOut: [email protected] [email protected] winFocus=false 
05-31 15:39:02.180: V/browser(1310): BrowserActivity.onDestroy: [email protected] 
05-31 15:39:02.290: E/WindowManager(1310): Activity com.android.browser.BrowserActivity has leaked window [email protected] that was originally added here 
05-31 15:39:02.290: E/WindowManager(1310): android.view.WindowLeaked: Activity com.android.browser.BrowserActivity has leaked window [email protected] that was originally added here 
05-31 15:39:02.290: E/WindowManager(1310): at android.view.ViewRoot.<init>(ViewRoot.java:259) 
05-31 15:39:02.290: E/WindowManager(1310): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148) 
05-31 15:39:02.290: E/WindowManager(1310): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 
05-31 15:39:02.290: E/WindowManager(1310): at android.view.Window$LocalWindowManager.addView(Window.java:424) 
05-31 15:39:02.290: E/WindowManager(1310): at android.app.Dialog.show(Dialog.java:241) 
05-31 15:39:02.290: E/WindowManager(1310): at android.app.AlertDialog$Builder.show(AlertDialog.java:802) 
05-31 15:39:02.290: E/WindowManager(1310): at com.android.browser.BrowserActivity.onDownloadStart(BrowserActivity.java:3492) 
05-31 15:39:02.290: E/WindowManager(1310): at com.android.browser.Tab$4.onDownloadStart(Tab.java:1349) 
05-31 15:39:02.290: E/WindowManager(1310): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:388) 
05-31 15:39:02.290: E/WindowManager(1310): at android.os.Handler.dispatchMessage(Handler.java:99) 
05-31 15:39:02.290: E/WindowManager(1310): at android.os.Looper.loop(Looper.java:130) 
05-31 15:39:02.290: E/WindowManager(1310): at android.app.ActivityThread.main(ActivityThread.java:3689) 
05-31 15:39:02.290: E/WindowManager(1310): at java.lang.reflect.Method.invokeNative(Native Method) 
05-31 15:39:02.290: E/WindowManager(1310): at java.lang.reflect.Method.invoke(Method.java:507) 
05-31 15:39:02.290: E/WindowManager(1310): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875) 
05-31 15:39:02.290: E/WindowManager(1310): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633) 
05-31 15:39:02.290: E/WindowManager(1310): at dalvik.system.NativeStart.main(Native Method) 

[EDIT1]

@Override 
    protected void onMessage(Context context, Intent intent) { 
     Log.i(TAG, "Received message"); 
     String message = intent.getExtras().getString("price"); 

     Log.e(TAG, "message from gcm = " + message); 


     Uri Download_Uri = Uri.parse(message); 

     DownloadManager.Request r = new DownloadManager.Request(Download_Uri); 

    // This put the download in the same Download dir the browser uses 
    r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "RR3UPGRADE"); 



    // Notify user when download is completed 
    // (Seems to be available since Honeycomb only) 
    // r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); 

    // Start download 
    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); 
    dm.enqueue(r); 

     displayMessage(context, message); 
     // notifies user 
     generateNotification(context, message); 
    } 

06-04 11:38:05.624: I/ActivityManager(207): Starting: Intent { act=android.intent.action.VIEW dat=content://downloads/all_downloads/63 typ=application/vnd.android.package-archive flg=0x10000001 cmp=com.android.packageinstaller/.PackageInstallerActivity } from pid 421 
06-04 11:38:05.664: W/PackageParser(1203): Skipping dir: /all_downloads/63 
06-04 11:38:05.664: W/PackageInstaller(1203): Parse error when parsing manifest. Discontinuing installation 
+0

好的。我追溯了logcat错误,它看起来像下载有问题。 'W/PackageParser(1203):跳过目录:/ all_downloads/63' <==>'if(!sourceFile.isFile()){Slog.w(TAG,“Skipping dir:”+ mArchiveSourcePath); mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK;返回null; }'。看起来下载不成功。 – ozbek

+0

你有什么想法可以尝试解决这个问题吗? – turtleboy

+0

我已经尝试将下载管理器代码与AsyncTask放在一起,因为我发现了一个线程,指示要下载.apk,最好是异步执行它。它没有任何区别。 – turtleboy

回答

2

不用于摩托罗拉Defy迷你XT320 浏览器问题的精确解(这实际上可能是在一定意义上,摩托罗拉可能已经决定将限制在浏览器下载可疑文件正常运转,心里很不舒服,带有.a​​pk扩展名的文件可能非常危险),但实际上您可以直接请求DownloadManager下载您的文件。

有关示例代码,请参阅https://stackoverflow.com/a/9033224/1893766

+0

嗨,我用你的建议代码。我已经放在GcmIntentService的onMessage方法中。当我发出推送通知时,我将网址推送到手机上的新应用程序。您的代码确实会下载新文件,并将其存储在下载文件夹中,但在安装时出现由于清单导致的包错误。它在我的HTC oneX上运行良好,但在摩托罗拉defy xt320上无法安装。摩托罗拉正在运行2.3.6。如果我将浏览器指向服务器上的apk文件,它将下载该应用程序,但不会从下载文件夹安装。你有什么想法,为什么?谢谢 – turtleboy

+0

什么是您的应用程序的最低SDK版本?你可以在XT320上手动安装apk('adb install ozbek

+0

嗨,清单中的最小sdk设置为'8'。如果我将浏览器指向我的服务器上的apk文件,该应用程序就会安装。一旦安装了应用程序,我会创建一个推送通知,其中包含到达apk的URL(完全相同)。我收到推送并下载并存储在下载文件夹中。当我点击下载文件夹中的链接时,出现上面的包安装错误。 – turtleboy

0

我发现为什么下载管理器无法正常工作,但仍不确定原因。

// Start download 
    DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); 
    dm.enqueue(r); 

     displayMessage(context, message); 
     // notifies user 
     generateNotification(context, message); 

在上面的代码中,当我启动下载管理器时,对displayMessage()和generateNotification()的后续调用似乎会干扰下载。当我注释掉后面的代码时,DownloadManager似乎工作正常。就像我说不知道为什么。

+0

您是否尝试更改订单(以便下载管理器的请求最后)? – ozbek