小编sko*_*oke的帖子

使用应用程序之间的隐式意图的自定义操

我一直在尝试在两个单独的应用程序中获取两个活动,以使用自定义操作和隐式意图进行通信.

第一个应用程序(服务器)具有以下清单:

<application android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" android:theme="@style/AppTheme">
    <activity android:name="edu.example.sharing.manager.SecureFileShare"
        android:label="@string/title_activity_secure_file_share" android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="edu.example.sharing.action.STORE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>
    </activity>
</application>
Run Code Online (Sandbox Code Playgroud)

第二个应用程序创建如下意图:

File f = new File(s);
Uri fileUri = Uri.fromFile(f);
Intent intent = new Intent();
intent.setData(fileUri);
intent.setAction("edu.example.sharing.action.STORE");               
startActivityForResult(intent, STORE_REQUEST);
Run Code Online (Sandbox Code Playgroud)

它的表现是正常的.但是,当我尝试在客户端应用程序中发送intent时,我得到一个未找到活动的异常:

FATAL EXCEPTION: main
android.content.ActivityNotFoundException: No Activity found to handle Intent {act=edu.example.sharing.action.STORE dat=file:///storage/sdcard0/Download/Alarcon12-Rigoberto.pdf }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
at android.app.Activity.startActivityForResult(Activity.java:3351)
at android.app.Activity.startActivityForResult(Activity.java:3312)
Run Code Online (Sandbox Code Playgroud)

是什么导致Android无法识别第二个应用程序中声明的活动?谢谢.

android android-manifest android-intent

8
推荐指数
2
解决办法
6346
查看次数

发送意图的进程的Pid

我正在尝试发现向我发送意图的进程的进程ID或包名称.我不想将进程ID或包名称放在额外的(因为其他一些问题已经提出),因为我不想允许欺骗.我使用的代码是:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_secure_file_share);
    ...   

    Intent intent = getIntent();

    if (intent != null)
    {
        // get the caller
        String callingPackage = getAppNameByPID(getApplicationContext(),
               Binder.getCallingPid());
    ....
    }
 }
Run Code Online (Sandbox Code Playgroud)

getAppNameByPID翻译的PID的包名.问题是Binder.getCallingPid()始终返回收件人的PID(而不是调用者的PID).

你如何获得来电者的PID?

android android-intent

3
推荐指数
1
解决办法
4388
查看次数

标签 统计

android ×2

android-intent ×2

android-manifest ×1