将值从应用程序传递到另一个应用程序

问题描述 投票:-1回答:2

我有2个单独的应用程序。从App1,我需要将位置/目的地传递给App2,以便它将在弹出窗口中显示。

我尝试了Intents,SharedPreferences,甚至尝试了了解ContentProviders(不好)。似乎没有任何效果。

编辑

代码使用:

App1:com.myapp.rider-从骑士应用程序发送到驾驶员应用程序

Intent intent = new Intent("com.myapp.driver.Activities.DriverTracking");
intent.putExtra("destination", destination);
startActivity(intent);

App2:com.myapp.driver-从骑手那里获得价值

Bundle bundle = getIntent().getExtras();
mDestination = (String) bundle.get("destination");
Log.d("STATUS_1", "Destination = " + mDestination);

添加到App2中的清单:

<intent-filter>
   <action android:name="com.myapp.driver.Activities.DriverTracking" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

以上我已尝试并得到以下错误:

 Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.myapp.driver.Activities.DriverTracking (has extras) }
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1878)

图像

enter image description here

编辑

这里是错误:

05-27 14:45:12.940 21851-21851/com.myapp.rider E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.rider, PID: 21851
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.rider/com.myapp.rider.Activities.RiderHome}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent android.content.Intent.putExtras(android.os.Bundle)' on a null object reference
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
    at android.app.ActivityThread.access$1100(ActivityThread.java:221)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7224)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent android.content.Intent.putExtras(android.os.Bundle)' on a null object reference
    at com.myapp.rider.Activities.RiderHome.sendIntent(RiderHome.java:355)
android
2个回答
0
投票

App1:com.myapp.rider-从骑士应用程序发送到驾驶员应用程序

您正在设置一个Intent,期望它的<activity><intent-filter><action>

添加到App2中的清单:

在这里,您的操作是com.myapp.driver.Activities.DriverTracking。这与您的com.myapp.ryyde_driver.Activities.DriverTracking不符。您需要使Intent中的操作与Intent中的<action>相匹配。


0
投票

使用Intent + Bundle + PackageManager的固定解决方案:

<intent-filter>

在第二个应用程序的活动中,您需要获取捆绑包值:

Intent intent = new Intent();
intent.setComponent(new ComponentName("com.myapp.driver", "com.myapp.driver.Activities.DriverTracking"));
intent.putExtra("destination", destination);
startActivity(intent);
© www.soinside.com 2019 - 2024. All rights reserved.