mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
Try to work around devices whose calendar app only responds to EDIT, not INSERT Intent
git-svn-id: https://zxing.googlecode.com/svn/trunk@2428 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
54d32c794d
commit
238e8d6350
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.google.zxing.client.android.result;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.util.Log;
|
||||
import com.google.zxing.client.android.R;
|
||||
import com.google.zxing.client.result.CalendarParsedResult;
|
||||
import com.google.zxing.client.result.ParsedResult;
|
||||
|
@ -34,6 +36,8 @@ import java.util.Date;
|
|||
*/
|
||||
public final class CalendarResultHandler extends ResultHandler {
|
||||
|
||||
private static final String TAG = CalendarResultHandler.class.getSimpleName();
|
||||
|
||||
private static final int[] buttons = {
|
||||
R.string.button_add_calendar
|
||||
};
|
||||
|
@ -122,7 +126,16 @@ public final class CalendarResultHandler extends ResultHandler {
|
|||
intent.putExtra(Intent.EXTRA_EMAIL, attendees);
|
||||
// Documentation says this is either a String[] or comma-separated String, which is right?
|
||||
}
|
||||
launchIntent(intent);
|
||||
|
||||
try {
|
||||
// Do this manually at first
|
||||
rawLaunchIntent(intent);
|
||||
} catch (ActivityNotFoundException anfe) {
|
||||
Log.w(TAG, "No calendar app available that responds to " + Intent.ACTION_INSERT);
|
||||
// For calendar apps that don't like "INSERT":
|
||||
intent.setAction(Intent.ACTION_EDIT);
|
||||
launchIntent(intent); // Fail here for real if nothing can handle it
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -460,19 +460,32 @@ public abstract class ResultHandler {
|
|||
}
|
||||
}
|
||||
|
||||
void launchIntent(Intent intent) {
|
||||
/**
|
||||
* Like {@link #launchIntent(Intent)} but will tell you if it is not handle-able
|
||||
* via {@link ActivityNotFoundException}.
|
||||
*
|
||||
* @throws ActivityNotFoundException
|
||||
*/
|
||||
void rawLaunchIntent(Intent intent) {
|
||||
if (intent != null) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
Log.d(TAG, "Launching intent: " + intent + " with extras: " + intent.getExtras());
|
||||
try {
|
||||
activity.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle(R.string.app_name);
|
||||
builder.setMessage(R.string.msg_intent_failed);
|
||||
builder.setPositiveButton(R.string.button_ok, null);
|
||||
builder.show();
|
||||
}
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link #rawLaunchIntent(Intent)} but will show a user dialog if nothing is available to handle.
|
||||
*/
|
||||
void launchIntent(Intent intent) {
|
||||
try {
|
||||
rawLaunchIntent(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
builder.setTitle(R.string.app_name);
|
||||
builder.setMessage(R.string.msg_intent_failed);
|
||||
builder.setPositiveButton(R.string.button_ok, null);
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue