【问题标题】:error in implimantation of intent意图执行错误
【发布时间】:2017-07-28 19:47:29
【问题描述】:

我在 Eclipse 的 java 文件中编写了以下代码,以通过我的应用程序在我的 android 设备上启动 snapchat 应用程序。但是当我在我的 android 设备上运行它时,它显示“没有应用程序可以执行此操作”。

if(view.getId()==R.id.LaunchSnapchat){
    intent= new Intent(android.content.Intent.ACTION_VIEW); 
    intent.setData(Uri.parse("snapchat://details?id=com.snapchat.android&hl=en&rdid=com.snapchat.android"));
    chooser=Intent.createChooser(intent,"Launch Snapchat");
    startActivity(chooser);
}

解决办法是什么??

【问题讨论】:

  • 如果您想直接启动 snapchat,请将 package 设置为您的意图。
  • 检查我的答案

标签: java android eclipse android-intent


【解决方案1】:

简单的答案,取自here

如果您不知道主要活动,则可以使用包名称来启动应用程序。

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.snapchat.android");
if (launchIntent != null) { 
    startActivity(launchIntent);//null pointer check in case package name was not found
}

【讨论】:

    【解决方案2】:

    试试这个

    Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("*/*");
        intent.setPackage("com.snapchat.android");
        startActivity(Intent.createChooser(intent, "Open Snapchat"));
    

    这也是因为你没有安装 snapchat(模拟器)

    if(view.getId()==R.id.LaunchSnapchat){
        intent= new Intent(android.content.Intent.ACTION_VIEW); 
        intent.setData(Uri.parse("snapchat://details?id=com.snapchat.android&hl=en&rdid=com.snapchat.android"));
        chooser=Intent.createChooser(intent,"Launch Snapchat");
        startActivity(chooser);
    }
    

    【讨论】:

      猜你喜欢
      • 2022-07-20
      • 1970-01-01
      • 1970-01-01
      • 2011-01-18
      • 2022-06-13
      • 2021-04-16
      • 2017-03-22
      • 2021-10-05
      • 2023-01-16
      相关资源
      最近更新 更多