-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_channel.java
More file actions
49 lines (42 loc) · 1.53 KB
/
Copy pathsample_channel.java
File metadata and controls
49 lines (42 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package <your package>;
import android.content.pm.ApplicationInfo;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class ChannelConfig {
private static final String DEFAULT_CHANNEL = "";
private static final String PREFIX = "META-INF/channel";
private static final String EXPRESSION = "_";
public static String getChannel() {
ApplicationInfo info = <your application context>.getApplicationInfo();
String sourceDir = info.sourceDir;
ZipFile zipFile = null;
try {
zipFile = new ZipFile(sourceDir);
Enumeration entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
String entryName = entry.getName();
if (entryName.startsWith(PREFIX)) {
String[] split = entryName.split(EXPRESSION);
if (split != null && split.length >= 2)
return entryName.substring(split[0].length() + 1);
else
return DEFAULT_CHANNEL;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (zipFile != null) {
try {
zipFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return DEFAULT_CHANNEL;
}
}