Copyright (c) 2015, Chris Greenhalgh
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met...
If you think the Android project wototoplayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
/*www.java2s.com*/
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/package org.opensharingtoolkit.player;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.content.ContentResolver;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import org.apache.cordova.*;
publicclass CordovaApp extends CordovaActivity
{
@Override
publicvoid onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.init();
// Set by <content src="index.html" /> in config.xml
if (!checkIntent(getIntent()))
loadUrl(launchUrl);
}
@Override
protectedvoid onNewIntent(Intent intent) {
checkIntent(intent);
}
staticint MAX_LENGTH = 10000;
privateboolean checkIntent(Intent intent) {
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
Uri uri = intent.getData();
if ("x-wototo".equals(uri.getScheme())) {
String url = uri.toString();
url = "http"+url.substring(8);
if (url.contains("?"))
url = url+"&wototo=1";
else
url = url+"?wototo=1";
Log.d(TAG,"Load from rewritted wototo intent "+url);
loadUrl(url);
}
elseif ("content".equals(uri.getScheme())) {
Log.d(TAG,"Check for redirect in content "+uri);
try {
InputStream is = this.getContentResolver().openInputStream(uri);
Reader r = new InputStreamReader(new BufferedInputStream(is), "UTF-8");
StringBuilder sb = new StringBuilder();
char buf[] = newchar[MAX_LENGTH];
int len = r.read(buf);
is.close();
if (len>=0) {
String in = new String(buf, 0, len);
Log.d(TAG,"Read content "+in);
Matcher m = Pattern.compile("<meta\\s+http-equiv=\"refresh\"\\s+content=\"[^;\"]*;?url=([^\"]*)\"").matcher(in);
if (m.find()) {
String url = m.group(1).replace("&", "&");
Log.d(TAG,"Load from redirect "+url);
loadUrl(url);
return true;
}
}
else
Log.w(TAG,"Could not read any characters from "+uri);
}
catch (Exception e) {
Log.w(TAG,"Error reading "+uri+": "+e);
}
}
else {
Log.d(TAG,"Load from intent "+uri);
loadUrl(uri.toString());
}
return true;
}
return false;
}
}