简体   繁体   English

Android-Java-未找到处理意图的活动

[英]Android - Java - No Activity Found to Handle Intent

I am trying to create an Android / Java plugin for the cross-platform program Phonegap / Cordova 3.2. 我正在尝试为跨平台程序Phonegap / Cordova 3.2创建一个Android / Java插件。 I am following several tutorials but can't get the simplest plugin to work. 我正在关注几个教程,但无法使用最简单的插件。

Currently I am working on the idea that my Java code is just wrong somewhere. 目前,我正在研究我的Java代码在某处错误的想法。

Could someone please review the following code and advise if there is something obviously wrong? 有人可以查看下面的代码,并告知是否明显存在问题吗?

The error I keep getting is 我不断收到的错误是

Exception: No Activity found to handle Intent { act=android.intent.action.MEDIA_SCANNER_SCAN_FILE dat=file:///{"fullPath":"media\/test.mp3"} }

Here is my .java file 这是我的.java文件

package org.media.scan;

import java.io.File;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

import android.content.Intent;
import android.net.Uri;

public class Scan extends CordovaPlugin {

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

    try {
        if ( action.equals("addRemove") ) {

            String filePath = args.getString(0);

            filePath = filePath.replaceAll("^file://", "");

            if (filePath.equals("")) {
                callbackContext.error("null path passed");
                return false;
            }               

            File file = new File(filePath);

            Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            scanIntent.setData(Uri.fromFile(file));

            this.cordova.getActivity().startActivity( scanIntent );
            callbackContext.success("good");
            return true;

        } else {
            callbackContext.error("invalid action phrase");

        }

        return false;

    } catch(Exception e) {

        System.err.println("Exception: " + e.getMessage());
        callbackContext.error(e.getMessage());
        return false;
    }




}

}

I am calling my Java code with this .js code 我正在用此.js代码调用Java代码

var Scan = {
createEvent:function (fullPath, successCallback, errorCallback) {
    cordova.exec(
        successCallback, // success callback function
        errorCallback, // error callback function
        'Scan', // mapped to our native Java class
        'addRemove', // with this action name
        [
            {                  
                "fullPath":fullPath
            }
        ]
    );
}
}

module.exports = Scan;

It's a broadcast action not activity action, you should use the send broadcast method for this kind of action! 这是广播操作而不是活动操作,您应使用发送广播方法进行这种操作!

http://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_SCANNER_SCAN_FILE http://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_SCANNER_SCAN_FILE

This is the wrong line in code " this.cordova.getActivity().startActivity( scanIntent ); " 这是代码“ this.cordova.getActivity()。startActivity(scanIntent);”中的错误行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到可处理意图的活动,Android - no activity found to handle intent, android Android未找到处理意图MediaScanner的活动 - Android no Activity Found to Handle Intent MediaScanner Android“严重错误,未找到任何处理意图的活动” - Android 'fatal error no activity found to handle intent' 找不到用于处理Intent的活动[Android studio] - No Activity found to handle Intent [Android studio] 找不到用于处理意图的活动{act = android.intent.action.View} - No activity found to handle intent { act=android.intent.action.View } 没有找到处理意图的活动{act=android,intent.action.VIEW} - No activity found to handle intent{act=android,intent.action.VIEW} Android:找不到用于处理Intent的活动(尝试向现有应用添加活动) - Android: No Activity found to handle Intent (trying to add an activity to exsisting app) 尝试将图片保存到 Android Java 中的外部存储时出现“No Activity found to handle Intent”错误 - “No Activity found to handle Intent” error when trying to save picture to external storage in Android Java Android错误:“ android.content.ActivityNotFoundException:未找到用于处理Intent的活动” - Android error : “android.content.ActivityNotFoundException: No Activity found to handle Intent” 找不到活动来处理意图错误 - No Activity found to handle intent errors
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM