我有下面的代码可以成功下载扩展文件,但我不知道在哪里添加我的 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/