android - 扩展文件 : Once the expansion files is downloaded start the Intent to next activity

标签 android apk-expansion-files

我有下面的代码可以成功下载扩展文件,但我不知道在哪里添加我的 Intent,这样一旦下载了扩展文件我就可以开始我的 Activity 了。

请帮忙。

try {
            Intent launchIntent = ExpansionFilesActivity.this.getIntent();
            Intent intentToLaunchThisActivityFromNotification = new Intent(ExpansionFilesActivity.this,
                ExpansionFilesActivity.this.getClass());
            intentToLaunchThisActivityFromNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intentToLaunchThisActivityFromNotification.setAction(launchIntent.getAction());

            if (launchIntent.getCategories() != null) {
            for (String category : launchIntent.getCategories()) {
                intentToLaunchThisActivityFromNotification.addCategory(category);
            }
            }

            // Build PendingIntent used to open this activity from
            // Notification
            PendingIntent pendingIntent = PendingIntent.getActivity(ExpansionFilesActivity.this, 0,
                intentToLaunchThisActivityFromNotification, PendingIntent.FLAG_UPDATE_CURRENT);
            // Request to start the download
            int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this, pendingIntent, SampleDownloaderService.class);

            if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
            // The DownloaderService has started downloading the
            // files,
            // show progress
            initializeDownloadUI();
            return;
            } // otherwise, download not needed so we fall through to
              // starting the movie
        } catch (NameNotFoundException e) {
            Log.e(LOG_TAG, "Cannot find own package! MAYDAY!");
            e.printStackTrace();
        }
        }

最佳答案

Android 开发人员指南中的示例如下:

@Override
public void onCreate(Bundle savedInstanceState) {
    // Check if expansion files are available before going any further
    if (!expansionFilesDelivered()) {
        // Build an Intent to start this activity from the Notification
        Intent notifierIntent = new Intent(this, MainActivity.getClass());
        notifierIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                                Intent.FLAG_ACTIVITY_CLEAR_TOP);
        ...
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
                notifierIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        // Start the download service (if required)
        int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this,
                        pendingIntent, SampleDownloaderService.class);
        // If download has started, initialize this activity to show download progress
        if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
            // This is where you do set up to display the download progress (next step)
            ...
            return;
        } // If the download wasn't necessary, fall through to start the app
    }
    startApp(); // Expansion files are available, start the app
}

所以首先你要看看它是否可用。如果未在服务中下载,完成后会通知用户数据可用。

关于android - 扩展文件 : Once the expansion files is downloaded start the Intent to next activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16066445/

相关文章:

Android facebook sdk 4.0 ProfileTracker onCurrentProfileChanged 永远不会被调用

android - android 中的 Lambda 表达式

java - 我应该如何将变量传递给另一个类?

android - 检查 APK 扩展 obb 有效性的最佳实践

android - 如何使用 jobb 工具创建 OBB 文件 Android

android - Gradle无法解析支持库

android - 当我们在任何 Activity 中单击主页时,关闭整个应用程序将关闭

Android 6.0权限及挂载OBB

android - 在测试版和发布版中处理 APK 扩展文件