Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 打印后返回启动器屏幕_Java_Android_Android Intent_Cycle - Fatal编程技术网

Java 打印后返回启动器屏幕

Java 打印后返回启动器屏幕,java,android,android-intent,cycle,Java,Android,Android Intent,Cycle,我正在Android studio中编写一个应用程序。现在,我希望我的应用程序永远不会关闭,并作为一个循环工作。我知道我可以使用Intent类完成这项工作,并为应用程序中的所有活动配置Manifest.xml文件 但要打印,我要在应用程序之外使用printsettings进行打印预览。此时,打印完成后,预览将关闭并(自动)返回到我的上一个活动(打印预览之前的活动)。现在,我想回到startpage(category.LAUNCHER),而不是之前的活动 但这不适用于使用Intent类编程,因为没

我正在Android studio中编写一个应用程序。现在,我希望我的应用程序永远不会关闭,并作为一个循环工作。我知道我可以使用Intent类完成这项工作,并为应用程序中的所有活动配置Manifest.xml文件

但要打印,我要在应用程序之外使用printsettings进行打印预览。此时,打印完成后,预览将关闭并(自动)返回到我的上一个活动(打印预览之前的活动)。现在,我想回到startpage(category.LAUNCHER),而不是之前的活动

但这不适用于使用Intent类编程,因为没有printpreview的xml文件。因为它是一种创建位图文件并在我的应用程序之外打印的方法

 /**
 * Method which creates a bitmap of the picture with the Odisee logo and 
 * goes to the printpreviewpage with settings.
 *
 */
private void doPhotoPrint() {
    try {
        //Creates object from PrintHelper class
        PrintHelper photoPrinter = new PrintHelper(this);

        //Scales image
        photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FILL);

        // Find the last picture
        String[] projection = new String[]{
                MediaStore.Images.ImageColumns._ID,
                MediaStore.Images.ImageColumns.DATA,
                MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
                MediaStore.Images.ImageColumns.DATE_TAKEN,
                MediaStore.Images.ImageColumns.MIME_TYPE};
        final Cursor cursor = getApplicationContext().getContentResolver()
                .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null,
                        null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC");

        String imageLocation = null;

        if (cursor.moveToFirst()) {
            imageLocation = cursor.getString(1);

        }
        File imageFile = new File(imageLocation);

        //Creates bitmapfile to print
        if (imageFile.exists()) {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;

            //Gets the resources (last taken picture + Odisee logo)
            Bitmap bitmap = BitmapFactory.decodeFile(imageLocation);
            Bitmap bitmap2 = BitmapFactory.decodeResource(getResources(),R.drawable.logo_odisee2);
            Bitmap bmOverlay = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());

            //Draws the Odisee logo onto the picture
            Canvas canvas = new Canvas(bmOverlay);
            canvas.drawBitmap(bitmap, new Matrix(),null);
            canvas.drawBitmap(bitmap2,950,550,null);

            //Sets printer orientation to landscape
            photoPrinter.setOrientation(PrintHelper.ORIENTATION_LANDSCAPE);

            //Goes to screen to print the bitmap
            photoPrinter.printBitmap("photobooth", bmOverlay);
        }
    }catch (Exception e) {
        System.err.println("Fout!");
    }
}
如果我创建一个Intent对象,它将跳过printpreview部分,或者在打印后崩溃。所以我想知道是否有其他可能的方法来解决这个问题并保持应用程序运行

    <activity android:name=".startPagina">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


当我阅读文档时,您可以使用
PrintHelper.OnPrintFinishCallback
界面将回调发送到[,android.graphics.Bitmap,android.support.v4.print.PrintHelper.OnPrintFinishCallback](printBitmap),这样在打印完成后,您就可以启动应用程序的启动程序了activity@armanso我要试试看!谢谢你的帮助!