0

I've an app that uses GCM push notifications. When i push a notification on to the phones that i'm testing (HTC Desire C, Samsung mini etc), it works fine. The notification is the url of the app that has the bug fixes in.

What normally happens is the push is received, once clicked the browser open and the download starts. Once the download is complete, the user can click on the notification in the notification draw and the app installs/upgrades.

The problem is when i try to run this on the Motorola defy mini XT320. It can receive the push but the browser opens for as second or so before closing and the download is not started.

Has anyone any ideas why? Below is how i generate the notification along with the error. I can see a dialog box pop up for a split second as the browser open. I know the error may have something to do with this as it's a leaked window error. I don't create this dialog box, it's part of Android's browser activity.

Thanks in advance.

 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: android.widget.EditText@408d6ca0 mServedView=android.widget.EditText@408d6ca0 winFocus=false
05-31 15:39:02.170: V/InputMethodManager(1310): focusOut: android.webkit.WebView@408bb1a0 mServedView=android.widget.EditText@408d6ca0 winFocus=false
05-31 15:39:02.180: V/browser(1310): BrowserActivity.onDestroy: this=com.android.browser.BrowserActivity@407ec730
05-31 15:39:02.290: E/WindowManager(1310): Activity com.android.browser.BrowserActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@408da548 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 com.android.internal.policy.impl.PhoneWindow$DecorView@408da548 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
turtleboy
  • 8,210
  • 27
  • 100
  • 199
  • OK. I traced back the logcat error and it looks like something is wrong with the download. `W/PackageParser(1203): Skipping dir: /all_downloads/63` <==> `if (!sourceFile.isFile()) { Slog.w(TAG, "Skipping dir: " + mArchiveSourcePath); mParseError = PackageManager.INSTALL_PARSE_FAILED_NOT_APK; return null; }`. Looks like download was unsuccessful. – ozbek Jun 04 '13 at 12:23
  • Have you any ideas of what i could try to get around this? – turtleboy Jun 04 '13 at 12:35
  • I've tried placing the downloadManager code with an AsyncTask as i found a thread that indicates that to download an .apk, it's best to do it asynchronously. It made no difference. – turtleboy Jun 04 '13 at 12:37
  • Sorry, I think I am clueless from this point. – ozbek Jun 04 '13 at 12:45

2 Answers2

2

Not an exact solution for the Browser issue in Motorola Defy Mini XT320 (this actually could be a normal operation in a sense that Motorola may have decided to put restriction in Browser to download suspicious files, and heck, files with .apk extension could be very dangerous), but you could actually directly request the DownloadManager to download your files.

See https://stackoverflow.com/a/9033224/1893766 for an example code.

Community
  • 1
  • 1
ozbek
  • 20,955
  • 5
  • 61
  • 84
  • Hi, I've used your suggested code. I've placed in within the GcmIntentService onMessage method. When i make a push notification, i push the url to the new app on to the phone. Your code does download the new file and it is stored in the download folder but on installation there is a package error due to the manifest. It works fine on my HTC oneX, but on the Motorola defy xt320 it can't install. the motorola is running 2.3.6. if i point the browser to the apk file on the server it will download the app, but it won't install from the downloads folder. Have you any ideas why? thanks – turtleboy Jun 04 '13 at 10:48
  • What's the minimum SDK version of your app? Can you install the apk manually (`adb install – ozbek Jun 04 '13 at 11:33
  • Hi, the minimum sdk is set to '8' in the manifest. The app installs ok if I point the browser to the apk file on my server. Once the app is installed, i create a push notification that has the url to the apk,(exactly the same). I receive the push and it downloads and is stored in the downloads folder. It is when i click on the link in the downloads folder i get the above package install error. – turtleboy Jun 04 '13 at 11:49
  • one thing i have noticed. when i install the app from the browser in the first place, it has the url under the apk name in the list in downloads. When i have downloaded the app from a push/downloadManager, only the name of the apk is displayed in the downloads list. – turtleboy Jun 04 '13 at 11:51
  • Hmmm... 1. You should not be able to install exact same .apk twice through PackageInstaller (this is normal). 2. Hope the .apk on the server is not corrupted? – ozbek Jun 04 '13 at 12:07
  • I can install the exact same .apk with all the other phones i've tested it on, just not the motorola. The apk on the server isn't corrupt as it downloads and installs ok. The place where it's going wrong is if the phone is pointed to the same apk from the downloads folder – turtleboy Jun 04 '13 at 12:27
0

I've found out why the download manager was not working properly but still unsure why.

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

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

.

In the above code when i start the download manager, the subsequent calls to displayMessage() and generateNotification() seem to interfere with the download. The DownloadManager seems to work fine when i comment out the subsequent code. Like i say not sure why.

turtleboy
  • 8,210
  • 27
  • 100
  • 199
  • Did you try to change the orders then (so that request to download manager comes last)? – ozbek Jun 10 '13 at 09:41