1

Bluetoothプリンターに画像を印刷するアプリケーションがあります。このアプリケーションはAndroid4.0ICSで正常に動作していますが、そのうちの1つをAndroid 4.1ジェリービーンズにアップグレードすると、logcatでの印刷が停止しました。

W / System.err(19319):java.lang.SecurityException:Permission Denial:writing com.android.bluetooth.opp.BluetoothOppProvider uri content://com.android.bluetooth.opp/btopp from pid = 19319、uid = 10106 android.permission.ACCESS_BLUETOOTH_SHAREまたはgrantUriPermission()が必要です

問題は、その許可を宣言していることです。したがって、このエラーは私たちには意味がありません。これが私たちのマニフェストからの行です

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.turner.itstrategy.LumenboxClient"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="11" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_BLUETOOTH_SHARE"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.VIBRATE" />

     (stuff removed)
</manifest>

印刷に使用しているコードは次のとおりです。このコードは、stackoverflowなどの例から抜粋したものです。

ContentValues values = new ContentValues();

String path = Environment.getExternalStorageDirectory().toString();
File imageFile = new File(path, "CurrentLumenboxPrint.jpg");

//build the message to send on BT
values.put(BluetoothShare.URI, Uri.fromFile(imageFile).toString());
values.put(BluetoothShare.MIMETYPE, "image/jpeg");
values.put(BluetoothShare.DESTINATION, device.getAddress());
values.put(BluetoothShare.DIRECTION, BluetoothShare.DIRECTION_OUTBOUND);
Long ts = System.currentTimeMillis();
values.put(BluetoothShare.TIMESTAMP, ts);

// Here is where the exception happens      
final Uri contentUri = getApplicationContext().getContentResolver().insert(BluetoothShare.CONTENT_URI, values);

今、私たちは水中で死んでいます。アドバイスをいただければ幸いです。

4

1 に答える 1

6

これは 4.1 では動作しないことがわかりました。コンテンツ プロバイダーに直接書き込む権限は、「署名済み」で保護されるようになりました。つまり、Bluetooth アプリの署名に使用したのと同じキーでアプリに署名する必要があります。

それで、これが私たちがそれをやった方法です。最初に共有インテントを使用してアプリに直接送信します。

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("image/jpeg");
sharingIntent.setComponent(new ComponentName("com.android.bluetooth", "com.android.bluetooth.opp.BluetoothOppLauncherActivity"));
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile));
startActivity(sharingIntent);

それは機能しますが、「デバイスの選択」UI がポップアップします。それを望まない場合は、インテントを処理android.bluetooth.devicepicker.action.LAUNCHしてブロードキャスト メッセージで応答する必要がありますandroid.bluetooth.devicepicker.action.DEVICE_SELECTED。ただし、ユーザーは引き続きセレクター ポップアップを取得できます。

更新:これを行う方法の完全な説明を含むブログ投稿を書きました。

于 2012-09-16T12:43:03.043 に答える