2016-07-07 6 views
0

私のアプリでインテントチューザーを使用してファイルを開こうとしています - 残念なことに、チューザーからの命題は...奇妙です。 pngファイルを選択すると、Drive PDF Viewerという1つのオプションのみが表示されます。しかし、デフォルトのファイルエクスプローラを使って同じファイルを開こうとすると、GaleryやPhotosを正しく使用することをお勧めします。Androidのインテントチューザー - 間違った命題

String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext.toLowerCase()); 
Log.i(TAG, mime); // <------------ image/png 
Intent intent= new Intent(Intent.ACTION_VIEW); 
intent.setType(mime); 
intent.setData(Uri.fromFile(file)); // <----- png file 
Intent chooser = Intent.createChooser(intent, "Choose an application to open with:"); 
chooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
context.startActivity(chooser); 

ここで何が間違っていますか?

+0

変更する場合:intent.setType( "image/*");できます? – motis10

+0

同じ話... – Lau

答えて

2

setDataAndTypeでこれを試してみてくださいinsted

String[] mimetypes = {"image/*"}; 
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); 
intent.addCategory(Intent.CATEGORY_OPENABLE); 
intent.setType("*/*"); 
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes); 

、これを試してみてください:

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(file), "image/*"); 
Intent chooser = Intent.createChooser(intent, "Choose an application to open with:"); 
context.startActivity(chooser); 

Javadocを参照してくださいしてくださいをのクラスのメソッドsetType(String型)インテント:
...
このメソッドは、以前に設定されたデータ(setData(Uri)など)を自動的にクリアします。
...

0

この5月には、あなたが

+0

これは、「このアクションに関連付けられたすべてのアプリはオフになっているか、ブロックされているか、インストールされていません」というメッセージでアクティビティを開きますが、GALERYアプリがインストールされているデフォルトのファイルエクスプローラで動作します) – Lau

+0

あなたはここで解決策/アイデアを得るかもしれませんhttp://codetheory.in/android-intent-filters/ –

0

試してみることができますaddindこれはMIME

Intent intent = new Intent(); 
intent.setType("image/*"); 
intent.setAction(Intent.ACTION_GET_CONTENT); 
startActivityForResult(Intent.createChooser(intent,"Select Image"),REQUEST_TAKE_GALLERY_IMAGE); 
+0

それは何も変わりません... – Lau

+0

これを更新しました。あなたのものと交換してみてください – Prashant

0

私は次のコードを使用したとき、私はあまりにも私のためのポップアップ同じメッセージを見てきました:

public class MainActivity extends AppCompatActivity { 
intent = new Intent(MainActivity.this, SecondActivity.class); 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.coordinator_main); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

    TextView textView = (TextView) findViewById(R.id.gotoA); 
    textView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      intent.putExtra("show 1",true); 
      startActivity(intent); 
     } 
    }); 

    TextView textView1 = (TextView) findViewById(R.id.gotoB); 
    textView1.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      intent.putExtra("show 2",true); 
      startActivity(intent); 
     } 
    }); 
} 

をので、私はその意図インスタンスを使用していますどこに意図コンストラクタをもたらしました。

public class MainActivity extends AppCompatActivity { 
Intent intent; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.coordinator_main); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

    TextView textView = (TextView) findViewById(R.id.gotoA); 
    textView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      intent = new Intent(MainActivity.this, SecondActivity.class); 
      intent.putExtra("show 1",true); 
      startActivity(intent); 
     } 
    }); 

    TextView textView1 = (TextView) findViewById(R.id.gotoB); 
    textView1.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      intent = new Intent(MainActivity.this, SecondActivity.class); 
      intent.putExtra("show 2",true); 
      startActivity(intent); 
     } 
    }); 
} 

私はこの問題を解決しました。

関連する問題