我正试图从我的应用程序打开Facebook应用程序。如果未安装FB App,它将在浏览器中打开该页面。当我点击facebook按钮时,没有任何内容出现。我添加了一些日志来知道代码停止的位置,但是我找不到错误?
这是我的代码
public class About extends MainActivity implements android.view.View.OnClickListener
{
Button fb;
static String TAG = "remote it";
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View contentView = inflater.inflate(R.layout.about, null, false);
mDrawer.addView(contentView, 0);
fb = (Button) contentView.findViewById(R.id.fb);
fb.setOnClickListener(this);
}
public static Intent getOpenFacebookIntent(Context context)
{
try
{
Log.d(TAG, "Entered try ");
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/1473553"));
}
catch (Exception e)
{
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/apauz"));
}
}
public void onClick(View v)
{ // TODO Auto-generated method stub
if (v.getId() == R.id.fb)
{
Log.d(TAG, "fb is clicked");
getOpenFacebookIntent(getApplicationContext());
}
}
}
logcat的
06-01 06:35:10.640: D/ExchangeService(1232): Received deviceId from Email app: null
06-01 06:35:10.640: D/ExchangeService(1232): !!! deviceId unknown; stopping self and retrying
06-01 06:35:11.600: D/remote it(1456): fb is clicked
06-01 06:35:11.600: D/remote it(1456): entered method
06-01 06:35:11.610: D/remote it(1456): try clicked
06-01 06:35:15.669: D/ExchangeService(1232): !!! EAS ExchangeService, onCreate
06-01 06:35:15.679: D/ExchangeService(1232): !!! EAS ExchangeService, onStartCommand, startingUp = false, running = false
06-01 06:35:15.679: W/ActivityManager(815): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
06-01 06:35:15.689: D/ExchangeService(1232): !!! Email application not found; stopping self
06-01 06:35:15.699: W/ActivityManager(815): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found
06-01 06:35:15.699: D/ExchangeService(1232): !!! EAS ExchangeService, onStartCommand, startingUp = true, running = false
06-01 06:35:15.719: E/ActivityThread(1232): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd9010 that was originally bound here
06-01 06:35:15.719: E/ActivityThread(1232): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd9010 that was originally bound here
06-01 06:35:15.719: E/ActivityThread(1232): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-01 06:35:15.719: E/ActivityThread(1232): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-01 06:35:15.719: E/ActivityThread(1232): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-01 06:35:15.719: E/ActivityThread(1232): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-01 06:35:15.719: E/ActivityThread(1232): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-01 06:35:15.719: E/ActivityThread(1232): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-01 06:35:15.719: E/ActivityThread(1232): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-01 06:35:15.719: E/ActivityThread(1232): at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
06-01 06:35:15.719: E/ActivityThread(1232): at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
06-01 06:35:15.719: E/ActivityThread(1232): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
06-01 06:35:15.719: E/ActivityThread(1232): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-01 06:35:15.719: E/ActivityThread(1232): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-01 06:35:15.719: E/ActivityThread(1232): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-01 06:35:15.719: E/ActivityThread(1232): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-01 06:35:15.719: E/ActivityThread(1232): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-01 06:35:15.719: E/ActivityThread(1232): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-01 06:35:15.719: E/ActivityThread(1232): at java.lang.Thread.run(Thread.java:856)
06-01 06:35:15.759: E/StrictMode(1232): null
06-01 06:35:15.759: E/StrictMode(1232): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd9010 that was originally bound here
06-01 06:35:15.759: E/StrictMode(1232): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-01 06:35:15.759: E/StrictMode(1232): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-01 06:35:15.759: E/StrictMode(1232): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-01 06:35:15.759: E/StrictMode(1232): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-01 06:35:15.759: E/StrictMode(1232): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-01 06:35:15.759: E/StrictMode(1232): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-01 06:35:15.759: E/StrictMode(1232): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-01 06:35:15.759: E/StrictMode(1232): at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116)
06-01 06:35:15.759: E/StrictMode(1232): at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249)
06-01 06:35:15.759: E/StrictMode(1232): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856)
06-01 06:35:15.759: E/StrictMode(1232): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-01 06:35:15.759: E/StrictMode(1232): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-01 06:35:15.759: E/StrictMode(1232): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-01 06:35:15.759: E/StrictMode(1232): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-01 06:35:15.759: E/StrictMode(1232): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-01 06:35:15.759: E/StrictMode(1232): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-01 06:35:15.759: E/StrictMode(1232): at java.lang.Thread.run(Thread.java:856)
06-01 06:35:15.759: W/ActivityManager(815): Unbind failed: could not find connection for android.os.BinderProxy@4111d050
06-01 06:35:15.769: E/ActivityThread(1232): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd8c68 that was originally bound here
06-01 06:35:15.769: E/ActivityThread(1232): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd8c68 that was originally bound here
06-01 06:35:15.769: E/ActivityThread(1232): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-01 06:35:15.769: E/ActivityThread(1232): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-01 06:35:15.769: E/ActivityThread(1232): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-01 06:35:15.769: E/ActivityThread(1232): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-01 06:35:15.769: E/ActivityThread(1232): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-01 06:35:15.769: E/ActivityThread(1232): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-01 06:35:15.769: E/ActivityThread(1232): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-01 06:35:15.769: E/ActivityThread(1232): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
06-01 06:35:15.769: E/ActivityThread(1232): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-01 06:35:15.769: E/ActivityThread(1232): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-01 06:35:15.769: E/ActivityThread(1232): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-01 06:35:15.769: E/ActivityThread(1232): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-01 06:35:15.769: E/ActivityThread(1232): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-01 06:35:15.769: E/ActivityThread(1232): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-01 06:35:15.769: E/ActivityThread(1232): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-01 06:35:15.769: E/ActivityThread(1232): at java.lang.Thread.run(Thread.java:856)
06-01 06:35:15.819: E/StrictMode(1232): null
06-01 06:35:15.819: E/StrictMode(1232): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40cd8c68 that was originally bound here
06-01 06:35:15.819: E/StrictMode(1232): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
06-01 06:35:15.819: E/StrictMode(1232): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
06-01 06:35:15.819: E/StrictMode(1232): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
06-01 06:35:15.819: E/StrictMode(1232): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
06-01 06:35:15.819: E/StrictMode(1232): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
06-01 06:35:15.819: E/StrictMode(1232): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
06-01 06:35:15.819: E/StrictMode(1232): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
06-01 06:35:15.819: E/StrictMode(1232): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
06-01 06:35:15.819: E/StrictMode(1232): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
06-01 06:35:15.819: E/StrictMode(1232): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
06-01 06:35:15.819: E/StrictMode(1232): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
06-01 06:35:15.819: E/StrictMode(1232): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-01 06:35:15.819: E/StrictMode(1232): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-01 06:35:15.819: E/StrictMode(1232): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-01 06:35:15.819: E/StrictMode(1232): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-01 06:35:15.819: E/StrictMode(1232): at java.lang.Thread.run(Thread.java:856)
06-01 06:35:15.829: W/ActivityManager(815): Unbind failed: could not find connection for android.os.BinderProxy@40f44170
06-01 06:35:15.849: D/dalvikvm(1232): GC_CONCURRENT freed 450K, 20% free 2471K/3060K, paused 5ms+8ms, total 115ms
06-01 06:35:16.459: E/ThrottleService(815): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
答案 0 :(得分:4)
您没有对正在创建的Intent
做任何事情。
在onClick方法中,您有:
getOpenFacebookIntent(getApplicationContext());
返回一个Intent。但是Intent只是对要执行的操作的描述。
您需要通过调用startActivity()来实际触发该操作:
startActivity(getOpenFacebookIntent(getApplicationContext()));