I don't want to make any app. I just want that when I click on the default camera app(screen shot is attached), then it normally open the camera. Then as I'll click the button for clicking the image, then I just want to show A Toast. For this I tried something. I just tried to receive the the broadcast Intent. The code is follows. But I am not getting the Toast. Please help me.
MainActivity.java
public class MainActivity extends Activity {
CameraReceiver myReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent("com.android.camera.NEW_PICTURE");
CameraReceiver myReceiver = new CameraReceiver();
sendBroadcast(intent);
}
private class CameraReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
abortBroadcast();
Log.d("New Photo Clicked", ">");
Cursor cursor = context.getContentResolver().query(
intent.getData(), null, null, null, null);
cursor.moveToFirst();
String image_path = cursor
.getString(cursor.getColumnIndex("_data"));
Toast.makeText(getApplicationContext(), "New Photo is Saved as : " + image_path,
1000).show();
}
}
@Override
public void onStart() {
super.onStart();
myReceiver = new CameraReceiver();
IntentFilter i = new IntentFilter("android.intent.action.CAMERA_BUTTON");
registerReceiver(myReceiver, i);
}
@Override
public void onResume() {
IntentFilter i = new IntentFilter("android.intent.action.CAMERA_BUTTON");
registerReceiver(myReceiver, i);
super.onResume();
}
@Override
public void onPause() {
unregisterReceiver(myReceiver);
super.onPause();
}
}
AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.defaultcamers.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".CameraReceiver"
android:enabled="true" >
<intent-filter android:priority="10000">
<action android:name="android.intent.action.CAMERA_BUTTON" />
<action android:name="com.android.camera.NEW_PICTURE" />
<action android:name="android.hardware.action.NEW_PICTURE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</receiver>
<class android:name=".CameraReceiver" >
</class>
</application>
Now when I am opening camera and trying to click the pic then I am getting "ClassNotFound Excaption" at "CameraReceiver.java".
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…