| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import org.xmlpull.v1.XmlPullParser; |
| 20 |
import org.xmlpull.v1.XmlPullParserException; |
| 21 |
|
| 22 |
import android.content.Intent; |
| 23 |
import android.content.pm.ActivityInfo; |
| 24 |
import android.content.pm.PackageManager; |
| 25 |
import android.content.res.XmlResourceParser; |
| 26 |
import android.os.Bundle; |
| 27 |
import android.util.AttributeSet; |
| 28 |
import android.util.Xml; |
| 29 |
|
| 30 |
import com.android.internal.util.XmlUtils; |
| 31 |
|
| 32 |
import java.io.IOException; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
@Deprecated |
| 46 |
public class AliasActivity extends Activity { |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public final String ALIAS_META_DATA = "android.app.alias"; |
| 54 |
|
| 55 |
@Override |
| 56 |
protected void onCreate(Bundle savedInstanceState) { |
| 57 |
super.onCreate(savedInstanceState); |
| 58 |
|
| 59 |
XmlResourceParser parser = null; |
| 60 |
try { |
| 61 |
ActivityInfo ai = getPackageManager().getActivityInfo( |
| 62 |
getComponentName(), PackageManager.GET_META_DATA); |
| 63 |
parser = ai.loadXmlMetaData(getPackageManager(), |
| 64 |
ALIAS_META_DATA); |
| 65 |
if (parser == null) { |
| 66 |
throw new RuntimeException("Alias requires a meta-data field " |
| 67 |
+ ALIAS_META_DATA); |
| 68 |
} |
| 69 |
|
| 70 |
Intent intent = parseAlias(parser); |
| 71 |
if (intent == null) { |
| 72 |
throw new RuntimeException( |
| 73 |
"No <intent> tag found in alias description"); |
| 74 |
} |
| 75 |
|
| 76 |
startActivity(intent); |
| 77 |
finish(); |
| 78 |
|
| 79 |
} catch (PackageManager.NameNotFoundException e) { |
| 80 |
throw new RuntimeException("Error parsing alias", e); |
| 81 |
} catch (XmlPullParserException e) { |
| 82 |
throw new RuntimeException("Error parsing alias", e); |
| 83 |
} catch (IOException e) { |
| 84 |
throw new RuntimeException("Error parsing alias", e); |
| 85 |
} finally { |
| 86 |
if (parser != null) parser.close(); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
private Intent parseAlias(XmlPullParser parser) |
| 91 |
throws XmlPullParserException, IOException { |
| 92 |
AttributeSet attrs = Xml.asAttributeSet(parser); |
| 93 |
|
| 94 |
Intent intent = null; |
| 95 |
|
| 96 |
int type; |
| 97 |
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 98 |
&& type != XmlPullParser.START_TAG) { |
| 99 |
} |
| 100 |
|
| 101 |
String nodeName = parser.getName(); |
| 102 |
if (!"alias".equals(nodeName)) { |
| 103 |
throw new RuntimeException( |
| 104 |
"Alias meta-data must start with <alias> tag; found" |
| 105 |
+ nodeName + " at " + parser.getPositionDescription()); |
| 106 |
} |
| 107 |
|
| 108 |
int outerDepth = parser.getDepth(); |
| 109 |
while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 110 |
&& (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 111 |
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 112 |
continue; |
| 113 |
} |
| 114 |
|
| 115 |
nodeName = parser.getName(); |
| 116 |
if ("intent".equals(nodeName)) { |
| 117 |
Intent gotIntent = Intent.parseIntent(getResources(), parser, attrs); |
| 118 |
if (intent == null) intent = gotIntent; |
| 119 |
} else { |
| 120 |
XmlUtils.skipCurrentTag(parser); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
return intent; |
| 125 |
} |
| 126 |
|
| 127 |
} |