2017-08-25 82 views
-2

我目前正在開發一個musicplayer應用程序,我希望將藝術家網站鏈接到Chrome自定義選項卡(我的手機上安裝了Chrome)。大多數鏈接工作正常,打開他們應該,但是當我想打開網站從想象龍我收到錯誤「沒有發現活動處理意圖」。鏈接看起來像其他人,但我的應用程序崩潰每次我想打開此鏈接。ChromeCustomTabs - 活動中的句柄意圖錯誤

這是我的錯誤日誌:

E/UncaughtException: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=www.imaginedragonsmusic.com/ (has extras) } 
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1815) 
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1513) 
        at android.app.Activity.startActivityForResult(Activity.java:3940) 
        at android.app.Activity.startActivityForResult(Activity.java:3888) 
        at android.app.Activity.startActivity(Activity.java:4211) 
        at android.support.v4.content.ContextCompat.startActivity(ContextCompat.java:141) 
        at android.support.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:262) 
        at com.mobileagreements.radio.liferadio.activities.SongDetailActivity.onClick(SongDetailActivity.java:160) 
        at android.view.View.performClick(View.java:5106) 
        at android.view.View$PerformClick.run(View.java:20329) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5912) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:372) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200) 

任何人都經歷了類似的問題,並能幫助我嗎?

+0

我的代碼開始活動之前,請使用ResolveActivity。欲瞭解更多信息:https://stackoverflow.com/a/29994483/5909385 –

+0

添加'http'到您的網址。 –

回答

0

嘗試從www.imaginedragonsmusic.com/

修改URL

http://www.imaginedragonsmusic.com/

使用下面的代碼:

if (!url.startsWith("http://") && !url.startsWith("https://")) 
    url = "http://" + url; 

希望它可以幫助!

0

下面是從應用

public class MainActivity extends AppCompatActivity { 

Button btChrome, btWebView; 
EditText etUrl; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    etUrl = (EditText) findViewById(R.id.etUrl); 
    btChrome = (Button) findViewById(R.id.btChrome); 
    btWebView = (Button) findViewById(R.id.btWebView); 

    btChrome.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      String url = etUrl.getText().toString().toLowerCase().trim(); 
      if (url.isEmpty()) etUrl.setError("Enter URL"); 
      else if (!url.startsWith("http://") && !url.startsWith("https://")) { 
       url = "http://" + url; 
       openChromeTabs(url); 
      } else { 
       openChromeTabs(url); 
      } 
     } 
    }); 

    btWebView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      String url = etUrl.getText().toString().toLowerCase().trim(); 
      if (url.isEmpty()) etUrl.setError("Enter URL"); 
      else if (!url.startsWith("http://") && !url.startsWith("https://")) { 
       url = "http://" + url; 
       openWebView(url); 
      } else { 
       openWebView(url); 
      } 


     } 
    }); 
} 

void openChromeTabs(String url) { 
    CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); 
    CustomTabsIntent customTabsIntent = builder.build(); 
    customTabsIntent.launchUrl(MainActivity.this, Uri.parse(url)); 
} 

void openWebView(String url){ 
    Intent intent = new Intent(MainActivity.this, WebViewActivity.class); 
    intent.putExtra("URL", url); 
    startActivity(intent); 
    } 
}