我正在开发一个用于android的库(jar),我遇到的情况是我希望我的类或方法只能在我的库中访问,但不能在我的库之外访问.使用no修饰符将使该类在该包中可访问,但我处于这样一种情况:如果没有public修饰符则不能使用此类,因为使用no修饰符将使其在我不想要的其他包中不可访问.例如,我有一个班级说,
public class Globals {
public static String thisDeviceAddress;
public static String thisDeviceIP;
public static String thisDeviceName = "";
}
Run Code Online (Sandbox Code Playgroud)
这个课程随处可见.问题是我希望它可以在我正在开发的库中访问,但不能在库外部访问.我已经知道使用注释@hide将解决问题.例如:
/**
* @hide
*/
class Globals {
public static String thisDeviceAddress;
public static String thisDeviceIP;
public static String thisDeviceName = "";
}
Run Code Online (Sandbox Code Playgroud)
我用Google搜索了很多,但找不到实施的方法@hide.只是在@hide没有图书馆的情况下使用并没有隐藏课程.所以,请给我适当的指导.任何要使用的库?任何出路来解决这个问题?
我的应用程序拍照然后上传它.由于拍摄的照片尺寸很大,我必须缩小尺寸然后再上传.因此,我使用以下代码来减少存储在SD卡中某处的相机所拍摄图像的大小.但是我不知道代码有什么问题,如果是肖像,图像会逆时针旋转90度,否则在横向模式拍摄时图像会很好.
以下是我用来减小大小的代码.
public File getReducedImage(File mediaFile){
Bitmap b = decodeFile(mediaFile);
return getfileFromBitmap(b, mediaFile.getPath());
}
private File getfileFromBitmap(Bitmap b, String path) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
b.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
//you can create a new file name "test.jpg" in sdcard folder.
File f = new File(path);
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
// remember close de FileOutput
fo.close();
Log.v(TAG, "returned");
return f;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.v(TAG, "Exception caught");
return null; …Run Code Online (Sandbox Code Playgroud) 我已尝试使用以下代码更改操作栏的背景.它适用于4.3但不低于4.3.使用以下代码,正在设置null背景即.旧的背景被删除但新的背景未被设置.请帮我.
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.testing);
}
/**
* Callback when button is clicked to change background
* @param v
*/
public void onStartClicked(View v) {
int Min = 0;
int Max = 2;
//Random number generator between 0 and 2 inclusive
int pos = Min + (int) (Math.random() * ((Max - Min) + 1));
if (pos == 0) {
getActionBar().setBackgroundDrawable(
getResources().getDrawable(R.drawable.header));
} else if (pos …Run Code Online (Sandbox Code Playgroud)