ChromeCustomTabs - 处理活动中的意图错误

时间:2017-08-25 07:13:16

标签: android android-intent chrome-custom-tabs

我目前正在开发一个音乐播放器应用,我想在其中链接艺术家网站和Chrome自定义标签(Chrome已安装在我的手机上)。大多数链接工作正常和开放,就像他们应该,但当我想从想象龙打开网站时,我收到错误“没有找到活动来处理意图”。 Link只是看起来像其他人,但我的应用程序每次打开此链接时都会崩溃。

这是我的错误日志:

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)

有没有人遇到类似的问题,能够帮助我?

2 个答案:

答案 0 :(得分:0)

尝试修改网址

来自www.imaginedragonsmusic.com/

http://www.imaginedragonsmusic.com/

使用以下代码:

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

希望它有所帮助!!!

答案 1 :(得分: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);
    }
}