试图创建一个应用程序来“清理”由 facebook.com/l.php 包裹的 url。代码编译得很好,我什至可以从 facebook 应用程序调用它,但是我得到一个黑屏,而且我解析的新 url 似乎从未得到处理。
对 Java 来说不是新手,但对 droid 来说是新手..... :-o
无论如何,表现为:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fusco.leetum.fblinkcleaner"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="fusco.leetum.fblinkcleaner.Cleaner"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" android:host="facebook.com" />
<data android:scheme="http" android:host="m.facebook.com" />
<data android:scheme="http" android:host="www.facebook.com" />
</intent-filter>
</activity>
</application>
</manifest>
并且活动 java ( finish() 在那里,因为如果用户启动它,它应该什么都不做,但是由于解析器代码在 onCreate() 方法中,它需要每次都启动):
package fusco.leetum.fblinkcleaner;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
public class Cleaner extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_cleaner);
final Intent intent = getIntent();
if (intent.getAction().equals(Intent.ACTION_VIEW)) {
final String baseurl = intent.getDataString();
String newurl = baseurl;
if (baseurl.indexOf("?") != -1) {
String[] parseurl = baseurl.substring(baseurl.indexOf("?")+3).split("%2F");
newurl = "http:/";
for (int i=2; i < parseurl.length; i++) {
newurl = "/"+parseurl[i];
}
}
final Intent viewnewpage = new Intent(Intent.ACTION_VIEW, Uri.parse(newurl));
startActivity(viewnewpage);
}
this.finish();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_cleaner, menu);
return true;
}
}