标签: android-intent

通过Intent从一个类传递数据到另一个类并且无法捕获它?

我有两个这样的String Arrays,

String[] htmlArray = {
      "file:///android_asset/Pinocchio/OPS/chapter-001.xml",
      "file:///android_asset/Pinocchio/OPS/chapter-002.xml",

      "file:///android_asset/Pinocchio/OPS/chapter-035.xml",
      "file:///android_asset/Pinocchio/OPS/chapter-035.xml" 
};

String[] htmlArray1 = {
      "file:///android_asset/Harry_Potter/OEBPS/part1.xhtml",
      "file:///android_asset/Harry_Potter/OEBPS/part2_split_000.xhtml",

      "file:///android_asset/Harry_Potter/OEBPS/part18_split_000.xhtml",
      "file:///android_asset/Harry_Potter/OEBPS/part18_split_001.xhtml", 
};
Run Code Online (Sandbox Code Playgroud)

然后,我把两个ImageView放在另一个类中,

private void init() {
    pino_cover = (ImageView) findViewById(R.id.pino_cover);
    pino_cover.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        Intent reader=new Intent(instance,ReaderScreen.class);
        reader.putExtra("pino",true);
        startActivity(reader);
      }
    });

    harry_cover=(ImageView) findViewById(R.id.harry_cover);
    harry_cover.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        Intent reader=new Intent(instance,ReaderScreen.class);
        reader.putExtra("harry",true);
        startActivity(reader);
      }
    });
  }
Run Code Online (Sandbox Code Playgroud)

然后,如果我点击Pino图像,我可以通过htmlArray获取数据.

Intent i=getIntent();
      Bundle b = i.getExtras();
       String newText = b.
       String setext=b.getString("harry");
      if (newText=="pino")    
        pages …
Run Code Online (Sandbox Code Playgroud)

android android-intent

0
推荐指数
1
解决办法
869
查看次数

调用另一个包中的活动(android)

我想调用另一个包中的活动....

比方说我Activity在我的package(package1)中有一个(activity1),我需要从我的activity1 调用另一个Activity(activity2)中的另一个package(activity2).

我试图在我的package1中导入package2但它没有用...有人能回答我并提供一些示例代码吗?

android package android-intent android-activity

0
推荐指数
1
解决办法
7573
查看次数

NotificationManager设置的Intent不会反映在activity的onResume()中

我有一个广播接收器,在收到某些东西后,会创建一个待定的意图,用一些数据打包它,然后用它来用NotificationManager创建一个通知.当NotificationManager恢复活动时,挂起意图中指定的活动始终读出原始挂起意图的数据 - 当广播接收器中的后续onReceive()设置时,它永远不会读出任何新数据.这是广播接收器的片段:

public void onReceive( Context context, Intent intent ) {
    String action = intent.getAction();

    if( action.equals( "someaction" ) ) {
        long now = System.currentTimeMillis();
        int icon = R.drawable.icon;
        CharSequence tickerText = context.getString( R.string.tickerText );
        CharSequence contentTitle = context.getString( R.string.contentTitle );
        CharSequence contentText = context.getString( R.string.contentText );
        Intent notificationIntent = new Intent( context, MyActivity.class );

        Log.d( TAG, "Creating notification with data = " + intent.getStringExtra( "somestring" ) );
        notificationIntent.putExtra( "somestring", intent.getStringExtra( "somestring" ) );
        notificationIntent.addFlags( Intent.FLAG_ACTIVITY_SINGLE_TOP );
        notificationIntent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK …
Run Code Online (Sandbox Code Playgroud)

notifications android android-intent android-activity android-pendingintent

0
推荐指数
1
解决办法
4890
查看次数

我在多个意图上得到"未知的服务启动结果"错误

我正在尝试使用从我的活动发送的意图来调用我的服务的某些功能.

这是我从活动发送意图的方式(在UI线程中):

Intent it = new Intent(MyService.INTENT_ACTIVITY_POSITION_CHANGED);
it.setClass(getApplicationContext(), MyService.class);
it.putExtra("posPercentX", x);
it.putExtra("posPercentY", y);
startService(it);
Run Code Online (Sandbox Code Playgroud)

这就是myStartCommand在MyService中的样子:

    @Override
    public int onStartCommand (Intent intent, int flags, int startId){
       super.onStartCommand(intent, flags, startId);

       if(intent.getAction().equals(INTENT_ACTIVITY_START)){
        Toast.makeText(this,"onStartCommand ...", Toast.LENGTH_SHORT).show();
       }else if(intent.getAction().equals(INTENT_ACTIVITY_POSITION_CHANGED)){
        // here comes some code to get extras from intent
        Log.d("INTENT_ACTIVITY_POSITION_CHANGED", "x=" + posX + " y=" + posY);
        //TODO preveri
       }
       return startId;
    }
Run Code Online (Sandbox Code Playgroud)

我接到几个电话后:

ERROR/ActivityManager(52): java.lang.IllegalArgumentException: Unknown service start result: 4
Run Code Online (Sandbox Code Playgroud)

为什么我会收到此错误?任何的想法?

service android android-intent

0
推荐指数
1
解决办法
1055
查看次数

加载默认的android web浏览器

我目前正在开发一个Android应用程序.我希望用户从列表视图中选择一个项目并加载在默认的android浏览器中使用所选选项分配的URL而不是使用webview,因为这意味着我必须有效地创建自己的Web浏览器.

感谢您的任何帮助,您可以提供

browser android android-intent

0
推荐指数
1
解决办法
1020
查看次数

如何在同一个 Android Intent 中以编程方式共享不同 MIME 类型的多个文件?

我正在开发一个 Android 应用程序,该应用程序已经使用以下方法通过蓝牙成功共享生成的 PDF 文件:

public static void sharePdfFile(Context ctx, String pathAndFile) {
    try {
        Intent share = new Intent(Intent.ACTION_SEND);

        share.setPackage("com.android.bluetooth");
        share.setType("application/pdf");
        share.putExtra(Intent.EXTRA_STREAM, Uri.parse(pathAndFile));
        share.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        ctx.startActivity(share);
    } catch (Exception e) {
        ExceptionDAO.Log(CATEGORY.SHARE_INTENT, e, ctx, e.getMessage(), true);
    }
}
Run Code Online (Sandbox Code Playgroud)

我被要求在此共享意图中包含第二个文件(CSV 格式),以便两个文件一起发送。我立即发现了这个问题,它解决了通过蓝牙发送多个文件的问题,但仅使用相同 MIME 类型的文件(该示例中的“video/*”)。

我已经找到了大量通配符 MIME 子类型的示例(“video/*”、“text/*”等),但此时我无法找到具有多个特定 MIME 类型集的 Intent 的任何示例(例如:“应用程序/pdf”和“文本/逗号分隔值”)。因此,我创建了一个使用“*/*”作为 MIME 类型的测试方法,希望能够解决问题。不幸的是,我的测试方法甚至还不足以激活蓝牙共享弹出窗口以选择附近的设备。

我不确定我做错了什么或遗漏了什么。我在调试时似乎无法捕获任何错误,所以我认为我仍然遗漏了一些东西。我确实知道 PDF 和 CSV 文件及其各自的 URI 都可以,因为这两个文件都可以通过原始方法很好地传输(我更改了现有方法上的 MIME 类型和 URI 以测试新的 CSV 文件。) 

这是我的测试方法:

public static void shareTwoFilesTest(Context ctx, String pathAndFile, String pathAndFile2) {
    try …
Run Code Online (Sandbox Code Playgroud)

android bluetooth android-intent mime-types

0
推荐指数
1
解决办法
3214
查看次数

如何在单击 Android Studio 按钮时发送邮件?

我想发送电子邮件,当单击按钮时,我想要基于电子邮件的应用程序列表。当我使用下面的源代码时,它会输出所有基于消息的应用程序,如图所示

Intent intent2 = new Intent(Intent.ACTION_SEND);
intent2.setData(Uri.parse("mailto:"));
intent2.setType("plain/text");
intent2.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
startActivity(intent2);
Run Code Online (Sandbox Code Playgroud)

当我单击按钮时,会显示此类应用程序

在此输入图像描述

但我只想要基于电子邮件的应用程序,例如。我应该改变什么才能获得这样的应用程序列表?

在此输入图像描述

email android android-intent android-studio

0
推荐指数
1
解决办法
2458
查看次数

如何从 Fragment.kt 文件调用 Activity?

class ProfileFragment : Fragment() {
    private lateinit var tvhelpcenter: TextView
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        return inflater.inflate(R.layout.fragment_profile, container, false)
        /*  val view = inflater?.inflate(
              R.layout.fragment_home,
              container, false
          )*/
        /*val tv_help_center: TextView? = view?.findViewById(R.id.tv_help_center)
        tv_help_center!!.setOnClickListener {
            requireActivity().run {
                startActivity(Intent(this, HelpCenterActivity::class.java))
                finish()
            }
        }*/
    }
}
Run Code Online (Sandbox Code Playgroud)

android android-intent android-fragments kotlin

0
推荐指数
1
解决办法
1442
查看次数

将值从 Activity 传递到适配器

我有活动 A 和 B。活动 B 使用回收视图 Adpater 来显示信息列表。从活动 A 中,我将意图发送到用于工具栏标题的活动 B。但我在 Adapter 类中也需要相同的意图。

那么如何将 Intent 值从 Activity A 传递到 B,并在适配器类中也使用相同的 Intent。

我的活动 A 有代码

Intent new = new Intent(itemView.getContext(), B.class);
                phy.putExtra("key","This is title");   itemView.getContext().startActivity(new);
Run Code Online (Sandbox Code Playgroud)

在活动 B 中,我有

   getSupportActionBar().setTitle(getIntent().getStringExtra("key"));
Run Code Online (Sandbox Code Playgroud)

我也想要适配器类中的键值。

活动B的代码是

Intent new = new Intent(itemView.getContext(), B.class);
                phy.putExtra("key","This is title");   itemView.getContext().startActivity(new);
Run Code Online (Sandbox Code Playgroud)

我的适配器类有

   getSupportActionBar().setTitle(getIntent().getStringExtra("key"));
Run Code Online (Sandbox Code Playgroud)

提前致谢。

java android adapter android-arrayadapter android-intent

0
推荐指数
1
解决办法
1844
查看次数

Android:未触发与包相关的意图

我正在开发一个启动器应用程序,我刚刚添加了一个广播接收器,我将使用它来更新应用程序列表。我最初尝试接收ACTION_PACKAGE_ADDEDACTION_PACKAGE_REMOVED因为它们似乎足以胜任这项工作,但没有一个被解雇,所以我添加了我认为有用的所有其他与包相关的操作,并尝试在活动中注册它们:

val intentFilter = IntentFilter()
        intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED)
        intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED)
        intentFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED)
        intentFilter.addAction(Intent.ACTION_PACKAGE_INSTALL)
        intentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED)
        val rec = AppsInstallationsReceiver()
        registerReceiver(rec, intentFilter)
Run Code Online (Sandbox Code Playgroud)

并体现:

<receiver android:name=".core.installed_apps.AppsInstallationsReceiver">
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_ADDED" />
                <action android:name="android.intent.action.PACKAGE_REMOVED" />
                <action android:name="android.intent.action.PACKAGE_FULLY_REMOVED" />
                <action android:name="android.intent.action.PACKAGE_INSTALL" />
                <action android:name="android.intent.action.PACKAGE_REPLACED" />
                <data android:scheme="package"/>
            </intent-filter>
        </receiver>
Run Code Online (Sandbox Code Playgroud)

接收器本身没什么特别的:

class AppsInstallationsReceiver : BroadcastReceiver() {

    override fun onReceive(p0: Context?, p1: Intent?) {
        //TODO
    }
}
Run Code Online (Sandbox Code Playgroud)

事实证明,我只收到PACKAGE_FULLY_REMOVED并且仅当它在清单中注册时才收到。现在这已经足够好了,但我需要一种方法来知道何时安装新应用程序。由于这是一个启动器应用程序,因此此功能至关重要。为什么我没有收到任何东西?当然,该活动仍然存在于后台,因为它被用作启动器。

android android-intent android-launcher

0
推荐指数
1
解决办法
1006
查看次数