简体   繁体   中英

No Activity found to handle Intent { act=android.intent.action.OPEN_DOCUMENT cat=[android.intent.category.OPENABLE] typ=/* }

Please help me. I am an absolute beginner. Can't find videos on it. Debugging the code is giving faults mentioned below. Can't understand the meaning of those. Please help with the correct code

app that tries to open file browser but I am getting debugging messages at

com.example.anirbitadak.translator.MainActivity.startsearch(MainActivity.java:59)
  at com.example.anirbitadak.translator.MainActivity.access$000(MainActivity.java:15)
  at com.example.anirbitadak.translator.MainActivity$1.onClick(MainActivity.java:47)*/

Activity:

package com.example.anirbitadak.translator;

import android.app.Activity;
import android.net.Uri;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.content.Intent;
import android.widget.Toast;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
Button upload, translate;
public static final int REQUEST_CODE = 12;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    upload = (Button) findViewById(R.id.upload);
    translate = (Button) findViewById(R.id.translate);
    upload.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v){
           startsearch();

        }
    });
  }

private void startsearch() {//declaration of startsearch();
    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.setType("/*.docx");
    //intent.setType("/*.pdf");
    //intent.setType("/*.doc");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(intent, REQUEST_CODE);

}

@Override
protected void onActivityResult(int requestcode, int resultcode, Intent data) {
    super.onActivityResult(requestcode, resultcode, data);

    if (requestcode == REQUEST_CODE && resultcode == Activity.RESULT_OK) {
        if (data != null) {
            Uri uri = data.getData();
           //Flashing the path
            Toast.makeText(this, "Uri:" + uri, Toast.LENGTH_LONG).show();
            Toast.makeText(this, "Path:" + uri.getPath(), Toast.LENGTH_LONG).show();
        }
    }

 }

}

Code looks good to me.

Are you sure there's a DocumentsProvider installed on the device that can handle .docx?

Are you sure your mime pattern is correct? The mime for docx is application/vnd.openxmlformats-officedocument.wordprocessingml.document . Regardless, it seems incorrect you are specifying it as starting with a "/", as mime types are slash separated but do not begin with an "/".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM