我要給名字不同screenshots
是與移動日曆和時間
請幫助的名稱..提前保存名稱截屏並具有移動時間和日期
感謝。我添加我的清單文件請看看。並請加進一步幫助 什麼我做錯了
public class MainActivity extends Activity implements Listener {
// private static final int CAMERA_REQUEST=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.getId() == R.id.button1) {
Bitmap bitmap = takeScreenshot();
ImageView imageView = (ImageView)findViewById(R.id.imageView);
imageView.setImageBitmap(bitmap);
saveBitmap(bitmap);
}
}
});}
public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
Calendar cal=Calendar.getInstance();
File f = new File(Environment.getExternalStorageDirectory()
// (cal.getTimeInMillis()+"jpg"));
+ File.separator+ (cal.getTimeInMillis()+"jpg"));
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onGpsStatusChanged(int event) {
// TODO Auto-generated method stub
}}
這是我的清單文件:
<xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.imagescreen"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我的logcat:
10-18 16:29:17.957: I/dalvikvm(91): Jit: resizing JitTable from 4096 to 8192
10-18 16:29:17.997: D/PermissionCache(36): checking android.permission.READ_FRAME_BUFFER for uid=1000 => granted (20166 us)
10-18 16:29:17.997: W/WindowManager(91): Failure taking screenshot for (230x409) to layer 21005
10-18 16:29:18.027: D/AndroidRuntime(527): Shutting down VM
10-18 16:29:18.067: D/dalvikvm(527): GC_CONCURRENT freed 98K, 77% free 480K/2048K, paused 1ms+1ms
10-18 16:29:18.077: I/AndroidRuntime(527): NOTE: attach of thread 'Binder Thread #3' failed
10-18 16:29:18.087: D/dalvikvm(538): Not late-enabling CheckJNI (already on)
10-18 16:29:18.128: I/ActivityManager(91): Start proc com.example.imagescreen for activity com.example.imagescreen/.MainActivity: pid=538 uid=10044 gids={1015}
10-18 16:29:18.377: W/NetworkManagementSocketTagger(91): setKernelCountSet(10044, 1) failed with errno -2
10-18 16:29:18.877: I/Process(91): Sending signal. PID: 538 SIG: 3
10-18 16:29:18.877: I/dalvikvm(538): threadid=3: reacting to signal 3
10-18 16:29:19.007: I/dalvikvm(538): Wrote stack traces to '/data/anr/traces.txt'
10-18 16:29:19.377: I/Process(91): Sending signal. PID: 538 SIG: 3
10-18 16:29:19.377: I/dalvikvm(538): threadid=3: reacting to signal 3
10-18 16:29:19.427: I/dalvikvm(538): Wrote stack traces to '/data/anr/traces.txt'
10-18 16:29:19.657: D/gralloc_goldfish(538): Emulator without GPU emulation detected.
10-18 16:29:19.737: I/ActivityManager(91): Displayed com.example.imagescreen/.MainActivity: +1s717ms
10-18 16:29:20.367: W/NetworkManagementSocketTagger(91): setKernelCountSet(10013, 0) failed with errno -2
10-18 16:29:20.387: W/InputManagerService(91): Starting input on non-focused client [email protected] (uid=10013 pid=189)
10-18 16:29:22.233: D/ExchangeService(391): Received deviceId from Email app: androidc259148960
10-18 16:29:22.233: D/ExchangeService(391): Reconciling accounts...
10-18 16:29:36.067: D/dalvikvm(538): GC_FOR_ALLOC freed 113K, 4% free 6680K/6919K, paused 76ms
10-18 16:29:36.097: I/dalvikvm-heap(538): Grow heap (frag case) to 8.153MB for 1639696-byte allocation
10-18 16:29:36.157: D/dalvikvm(538): GC_CONCURRENT freed 3K, 4% free 8278K/8583K, paused 6ms+4ms
10-18 16:30:10.347: W/ThrottleService(91): unable to find stats for iface rmnet0
我的位圖: 公共無效saveBitmap(位圖位圖){
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
File f = new File(Environment.getExternalStorageDirectory()
+ File.separator + "test.jpg");
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
那麼,這不是工作? – Piyush 2014-10-17 07:26:38
nup not working – 2014-10-17 07:38:10
必須檢查你是否有在清單文件中添加寫入和讀取外部存儲的權限 – Piyush 2014-10-17 07:38:57