小编Ela*_*adB的帖子

Android:Dagger 2和构造函数注入

我是匕首的新手,我的构造函数/方法注入似乎不起作用.不起作用意味着仍然请求注入的字段.

这是我的代码:

@Module
public class AppContextModule {

    private final Context appContext;

    public AppContextModule(Context appContext) {
        this.appContext = appContext;
    }

    @Singleton
    @Provides
    public Context getAppContext() {
        return appContext;
    }

}

@Singleton
@Component(modules = {AppContextModule.class})
public interface MyComponent {

    void inject(ActivitiesLifeCycleListener obj);

    void inject(WebViewManager obj);

    Context context();

}

public final class MyClass {

    private final WeakReference<Context> mAppContext;

    @Inject
    public MyClass(Context context)  {
        this.mAppContext = context
    }

}

public class MyActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        MyClass …
Run Code Online (Sandbox Code Playgroud)

java android dependency-injection dagger dagger-2

5
推荐指数
1
解决办法
3688
查看次数

Android:如何从图库中打开图片?

我在我的应用程序中创建了一个方法,将我的布局保存为图像并将其显示在库中.我正试图打开它,但我很难用所有的教程和不同的方法......

这是我的代码:

SimpleDateFormat mTimeFormat = new SimpleDateFormat("dd-MM-yyyy");
        Date mTime = new Date();
        String mStringTime = mTimeFormat.format(mTime);

        String fileFolder = "/orders";
        String fileName = "/order-"+mStringTime;
        File filePath = new File("/sdcard"+fileFolder+fileName+".png");
        Uri fileUri = Uri.fromFile(filePath);

        File createFolder = new File(Environment.getExternalStorageDirectory()+fileFolder);
        if (!createFolder.exists()){ //checks I don't create the same folder twice
            createFolder.mkdir();
        }

        View orderView = findViewById(R.id.tableOrder); //this is what i shall save
        orderView.setDrawingCacheEnabled(true);
        Bitmap bitmap = orderView.getDrawingCache();      

        try {
            FileOutputStream outputImage = new FileOutputStream(filePath);
            bitmap.compress(CompressFormat.PNG, 10, outputImage);
            outputImage.close();
            orderView.invalidate();     

            Intent intentScanner = …
Run Code Online (Sandbox Code Playgroud)

android image gallery actionview android-intent

3
推荐指数
1
解决办法
6832
查看次数