[Q] Get Location debbuging on device - Android Software Development

Please,
I developed an application that use the current location.
Testing on local I can send the Latitude and Longitude by the DDM5 and I didn't have problem.
When I tried to do the same thing on debugging device, didn't work and on DDM5 I can't send this information.
Is there any setup to try this ?
Here is the code
<code>
//manifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
//view.xml -> widget configure
private Location location;
private LocationManager lm;
private LocationListener locationListener;
//onCreate
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationListener = new MyLocationListener();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
//action
location.distanceTo........
private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc) {
if (loc != null) {
location = loc;
}
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
</code>
Thanks,
Luiz

I would like to know if anyone knows what is happening ?
if this is normal or no ?
when debug the android system on device, the Location API works normally or we need to simulate something ?
Thanks,
Luiz

Related

Animations not working

Ive got a checkbox which should set a textview visible while checked, and hide it when its not checked. I have also created two basic animations that should appear during hiding and showing of the textview (fadeIn and fadeOut). Heres my onclicklistener for the checkbox:
Code:
checkBox1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
fadeIn = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_in);
fadeOut = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out);
if (((CheckBox) v).isChecked()) {
fadeIn.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
textView1.setVisibility(View.VISIBLE);
}
});
textView1.startAnimation(fadeIn);
}
else {
fadeOut.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
textView1.setVisibility(View.GONE);
}
});
textView1.startAnimation(fadeOut);
}
}
});
And here are my two animations:
Code:
<!-- fade_in.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fillAfter="true"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
Code:
<!-- fade_out.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fillAfter="true"
android:fromAlpha="1.0"
android:toAlpha="0.0" />
My problem is that the fade animation only shows when I uncheck the checkbox (hide the textbox). When I try to check the box (show the textview) it just appears without showing the animation. Any help would be appreciated. Thanks in advance.
Edit: Had to move "textView1.setVisibility(View.VISIBLE);" into the onAnimationStart method.
Try this:
Code:
checkBox1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
fadeIn = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_in);
fadeOut = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out);
if (((CheckBox) v).isChecked()) {
fadeIn.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
textView1.setVisibility(View.VISIBLE);
}
});
textView1.setAlpha(0);
textView1.setVisibility(View.VISIBLE);
textView1.startAnimation(fadeIn);
}
else {
fadeOut.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
textView1.setVisibility(View.INVISIBLE);
}
});
textView1.startAnimation(fadeOut);
}
}
});

[Q] Same shell command works from console and doesn't work from Activity

//sorry for my english, if any
Hi. I'm using AIDE right on my device (Xperia NeoV, 4.1.B.0.587, root)
And i'm trying to inject key events through the same shell command:
"input keyevent 25" via "su", both in AIDE Console and separated Activity.
//volume-down key is not my target, just good for tests. I've tried different keys, same result.
Part of the code:
Code:
try {
java.lang.Process p = Runtime.getRuntime().exec("su");
DataOutputStream dos = new DataOutputStream(p.getOutputStream());
dos.writeBytes("input keyevent 25\n");
dos.flush();
} catch (IOException ex) {
//log any errors
}
So, when it goes in AIDE ConsoleApp - it pushes down volume.
But when it executes from my Activity - nothing happens (no error messages in log, dos != null);
Maybe there should be some specific permission on manifest?
"android.permission.ACCESS_SUPERUSER" - no changes.
Maybe there should be some trick in code? Or(and?) i'm very stupid. Also, maybe somewhere a whole listing of _simple_ keyInjection project exists?
I managed to solve it already. I'm using this class now:
public void RunAsRoot(String[] cmds){
Process p = null;
try {
p = Runtime.getRuntime().exec("su");
} catch (IOException e) {
e.printStackTrace();
}
DataOutputStream os = new DataOutputStream(p.getOutputStream());
for (String tmpCmd : cmds) {
try {
os.writeBytes(tmpCmd+"\n");
} catch (IOException e) {
e.printStackTrace();
}
}
try {
os.writeBytes("exit\n");
} catch (IOException e) {
e.printStackTrace();
}
try {
os.flush();
} catch (IOException e) {
e.printStackTrace();
}
Click to expand...
Click to collapse
Then simply call it via
String[] commands = {"command1", "command2", "command3", ...};
RunAsRoot(commands);
Click to expand...
Click to collapse
Thanks anyways!
Click to expand...
Click to collapse
Credits: @KrauseDroid
Our original thread i took it from:
http://forum.xda-developers.com/showthread.php?t=2725173
---------------------------------
Phone : Nexus 4
OS:
Pure KitKat 4.4.2 stock, no root, no mods
---------------------------------
4d 61 73 72 65 70 75 73 20 66 74 77
Gesendet von Tapatalk
Masrepus said:
Credits: @KrauseDroid
Our original thread i took it from:
http://forum.xda-developers.com/showthread.php?t=2725173
Click to expand...
Click to collapse
I saw that thread before creating own, and tried solutions from it. They works same way - only from ConsoleApp in AIDE.
Also, last method is the same as I'm already using, but I've tried to copy code in project - no progress.
In addition:
- superuser rights granted to both.
- test "ls" command put into dos object gives me same list of current dir in both projects, so commands seems to run.
Listing:
MainActivity:
Code:
package com.tsk.mk;
import android.app.*;
import android.content.*;
import android.os.*;
import android.widget.*;
import java.io.*;
public class MainActivity extends Activity {
public static TextView logView;
[user=439709]@override[/user]
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
logView = (TextView) findViewById(R.id.log);
log("creating sercice");
final MainActivity me = this;
new Thread() {
[user=439709]@override[/user]
public void run() {
log("thread.run");
startService(new Intent(me, MissedKeysService.class));
log("thread: service shoul'd be created");
}
}.start();
log("end of MA.onCreate method");
}
static void log(String message) {
logView.setText(logView.getText() + "\n" + message);
}
}
MissedKeysService:
Code:
package com.tsk.mk;
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
import java.io.*;
public class MissedKeysService extends Service {
private WindowManager windowManager;
private MissedKeysView mkv;
private WindowManager.LayoutParams params;
private DataOutputStream dos;
[user=439709]@override[/user]
public IBinder onBind(Intent intent) {
MainActivity.log("onBind called o_o");
return null;
}
[user=439709]@override[/user]
public void onCreate() {
MainActivity.log("Service.onCreate");
super.onCreate();
try {
java.lang.Process p = Runtime.getRuntime().exec("su");
dos = new DataOutputStream(p.getOutputStream());
} catch (IOException ex) {
MainActivity.log(ex.getMessage());
dos = null;
}
windowManager = (WindowManager)
getSystemService(WINDOW_SERVICE);
mkv = new MissedKeysView(this, this);
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
params.width = MissedKeysView.keySize;
params.height = MissedKeysView.keySize;
windowManager.addView(mkv, params);
MainActivity.log("Service started");
}
[user=439709]@override[/user]
public void onDestroy () {
super.onDestroy ();
if (mkv != null) windowManager.removeView(mkv);
MainActivity.log("Ssrvice is ended");
}
public void extend(boolean state) {
params.height = mkv.keySize * (state ? MissedKeysView.keys : 1);
windowManager.updateViewLayout(mkv, params);
}
public void sendKey(int code) {
if (dos == null) MainActivity.log("dos is null");
try {
dos.writeBytes("input keyevent " + code + "\n");
dos.flush();
MainActivity.log("" + code);
} catch (IOException e) {
MainActivity.log("wtf?");
}
}
}
MissedKeysView:
Code:
package com.tsk.mk;
import android.content.*;
import android.graphics.*;
import android.view.*;
import android.view.View.*;
import java.io.*;
public class MissedKeysView extends View
implements OnTouchListener {
final static int keySize = 64;
final static String[] labels = {":", "+", "-", "^", "v", "o", "<", ">"};
final private int[] codes = {-1, 24, 25, 19, 20, 23, 21, 22};
final static int keys = 3; //max shown keys
MissedKeysService mks;
Paint bgP; //background
Paint hbgP; //highlighted bg
Paint tP; //text
int selected = -1; //active key
public MissedKeysView(Context context, MissedKeysService mks) {
super(context);
this.mks = mks;
bgP = new Paint();
bgP.setARGB(64, 128, 128, 128);
hbgP = new Paint();
hbgP.setARGB(64, 255, 128, 0);
tP = new Paint();
tP.setARGB(128, 255, 255, 255);
tP.setTextSize(keySize);
tP.setTextAlign(Paint.Align.CENTER);
setOnTouchListener(this);
}
[user=439709]@override[/user]
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
for(int i=0; i<getHeight()/keySize; i++) {
canvas.drawCircle(keySize/2,
keySize/2 + i*keySize, keySize/2,
(i == selected ? hbgP : bgP));
canvas.drawText(labels[i], keySize/2, i*keySize + keySize*3/4, tP);
}
}
[user=439709]@override[/user]
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
selected = (int) (event.getY()/keySize);
if (selected == 0) mks.extend((int) getHeight() <= keySize);
else mks.sendKey(codes[selected]);
break;
case MotionEvent.ACTION_UP:
selected =-1;
}
invalidate();
return super.onTouchEvent(event);
}
}
AndroidManifest:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tsk.mk"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="11" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".MainActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MissedKeysService"
android:exported="true" >
</service>
</application>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.INJECT_EVENTS" />
</manifest>
@Torsionick do you have the permission INJECT_EVENTS
---------------------------------
Phone : Nexus 4
OS:
Pure KitKat 4.4.2 stock, no root, no mods
---------------------------------
4d 61 73 72 65 70 75 73 20 66 74 77
Gesendet von Tapatalk
Masrepus said:
@Torsionick do you have the permission INJECT_EVENTS
Click to expand...
Click to collapse
Thanks for participating in solving.
The reason was somewhere else - after executing "export LD_LIBRARY_PATH=/system/lib" all works fine. Thread is over.

[Q] Populating listview from custom class

Hello,
I'm trying to populate a listview from a custom class but i don't seem able to do it. I run the code showed below and eventhought i've got no errors on build the elements aren't shown on screen. Any help with this would be very appreaciated.
The code's below!
The main_activity.xml:
HTML:
<LinearLayout xmlns:android="link"
xmlns:tools="link" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.angelo.gamerquiz.WallpaperSelector"
android:background="@drawable/background"
android:orientation="vertical"
android:weightSum="1">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/lista_background" />
</LinearLayout>
The single_row.xml:
HTML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="link"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/textView2" />
</LinearLayout>
And then the custom class code:
Code:
public class CustomAdapter extends BaseAdapter {
private Context mContext;
private Integer[] imgID;
public CustomAdapter(Context context, Integer[] imgID){
super();
mContext = context;
this.imgID = imgID;
}
[user=439709]@override[/user]
public int getCount() {
return 0;
}
[user=439709]@override[/user]
public Object getItem(int position) {
return null;
}
[user=439709]@override[/user]
public long getItemId(int position) {
return 0;
}
[user=439709]@override[/user]
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.single_row, null);
TextView tf = (TextView) convertView.findViewById(R.id.textView2);
tf.setText("Position " + String.valueOf(position));
return null;
}
}
And finally, the main class from where i call my custom class:
Code:
ListView listView;
Integer[] imageID = {R.drawable.ezio1_thumbnail};
[user=439709]@override[/user]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wallpaper_selector);
listView = (ListView) findViewById(R.id.lista_background);
Log.d("LVCREATED","TRUE");
CustomAdapter adapter = new CustomAdapter(this, imageID);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
[user=439709]@override[/user]
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), "You clicked at position " + position, Toast.LENGTH_SHORT);
}
});
}
Thank you!
NOTE: Nevermind where it says "link" when i posted this i got the message that i wouldn't be able to post links lol
Well:
1. Why would you want to use BaseAdapter and not ArrayAdapter if the latter is easier to use?
2. If you do want to use BaseAdapter then all the methods you override should work. If getCount() always returns 0 then the listview thinks there are just no entries inside the adapter and simply aborts the creation of any list items. getCount must return the length of the array of list entries, in your case the Integer[] imgID. Then if getItem returns null this won't work either, same thing if getView simply returns null....
So:
Use ArrayAdapter, then you only have to override the getView method.
And: after you prepared your convertView, why dont you use it as a return value
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
stock Recovery
Recovery: TWRP 2.8.2.0
Masrepus said:
Well:
1. Why would you want to use BaseAdapter and not ArrayAdapter if the latter is easier to use?
2. If you do want to use BaseAdapter then all the methods you override should work. If getCount() always returns 0 then the listview thinks there are just no entries inside the adapter and simply aborts the creation of any list items. getCount must return the length of the array of list entries, in your case the Integer[] imgID. Then if getItem returns null this won't work either, same thing if getView simply returns null....
So:
Use ArrayAdapter, then you only have to override the getView method.
And: after you prepared your convertView, why dont you use it as a return value
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
stock Recovery
Recovery: TWRP 2.8.2.0
Click to expand...
Click to collapse
Thank you for your answer!
I've followed your advice and changed it to an array adapter but it still is not working. Here's my custom class code.
Code:
public class CustomAdapter extends ArrayAdapter<Integer> {
private final Context context;
private final Integer[] values;
public CustomAdapter(Context context, Integer[] values) {
super(context, R.layout.single_row);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.single_row, parent, false);
ImageButton imgbt = (ImageButton) rowView.findViewById(R.id.wallpaperButton);
Log.d("VALUE",String.valueOf(values[position]));
imgbt.setImageResource(values[position]);
return rowView;
}
}
Any idea why?
Two questions:
What's the parameter that an ArrayAdapter receives, which in this case is "Integer" and why the use of super in the constructor?
Thank you.
ratedam said:
Thank you for your answer!
I've followed your advice and changed it to an array adapter but it still is not working. Here's my custom class code.
Code:
public class CustomAdapter extends ArrayAdapter<Integer> {
private final Context context;
private final Integer[] values;
public CustomAdapter(Context context, Integer[] values) {
super(context, R.layout.single_row);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.single_row, parent, false);
ImageButton imgbt = (ImageButton) rowView.findViewById(R.id.wallpaperButton);
Log.d("VALUE",String.valueOf(values[position]));
imgbt.setImageResource(values[position]);
return rowView;
}
}
Any idea why?
Two questions:
What's the parameter that an ArrayAdapter receives, which in this case is "Integer" and why the use of super in the constructor?
Thank you.
Click to expand...
Click to collapse
Mhh.. I think the problem lies within the inflation process, try this: View rowView = View.inflate(context, R.layout.single_row, null);
There could be a problem because you try to inflate the view inside a parent view and it somehow doesn't like that.
The parameter tells the adapter what kind of array it will receive, in this case an Integer[]
It is required by the base class, but i have no idea how the super constructor works. Just take it as given or google it
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
Recovery: TWRP 2.8.2.0
Masrepus said:
Mhh.. I think the problem lies within the inflation process, try this: View rowView = View.inflate(context, R.layout.single_row, null);
There could be a problem because you try to inflate the view inside a parent view and it somehow doesn't like that.
The parameter tells the adapter what kind of array it will receive, in this case an Integer[]
It is required by the base class, but i have no idea how the super constructor works. Just take it as given or google it
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
Recovery: TWRP 2.8.2.0
Click to expand...
Click to collapse
Thank you for your prompt response,
The problem was really in the super constructor.
I changed it from this super(context, R.layout.single_row); to this super(context, R.layout.single_row, values); and it worked.
But now i have another problem, i click it but doesn't show anything. Any idea? No errors neither.
EDIT:Solved.
I removed the onitemclicklistener from the main function and inserted it on the customadapter created class like this:
Code:
ImageButton imgbt = (ImageButton) rowView.findViewById(R.id.wallpaperButton);
imgbt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("CLICKED","BUTTONCLICKED");
Log.d("cenas","cenas" + position);
}
});
And i get the pretended output.
Thank you very much for your help.
Very good! Great that i helped you
--------------------
Phone: Nexus 4
OS: rooted Lollipop LRX21T
Bootloader: unlocked
Recovery: TWRP 2.8.2.0

Record Movie in Background

Hallo,
i would to like to record a movie in a Service but it faild and I have no idea.
Thank you for help.
Manifest File
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.mm.googlefit">
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:allowBackup="true"
android:icon="@mipmap/google_fit"
android:label="@string/app_name"
android:supportsRtl="true">
<activity android:name=".MainActivity"
android:screenOrientation="portrait"
android:excludeFromRecents="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".StartService"
android:screenOrientation="portrait"
android:excludeFromRecents="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".CamcorderReciver" android:exported="false"/>
</application>
</manifest>
In the MainActivity I create a shortcut.
Code:
private void ShortcutIcon(){
Intent shortcutIntent = new Intent(getApplicationContext(), StartService.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Test");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.google_fit));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
After I cklick on the shourtcout that will start this Activity and this start a Service.
Code:
public class StartService extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, CamcorderReciver.class);
startService(intent);
finish();
}
}
This code start a Service and the Service start the MediaRecoder
Code:
public class CamcorderReciver extends Service {
private static final String TAG = "MediaService";
private boolean isRunning = false;
@Override
public void onCreate() {
Log.e(TAG, "Service onCreate");
isRunning = true;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e(TAG, "Service onStartCommand");
Thread thread = new Thread() {
@Override
public void run() {
try {
MediaRecorder.MediaRecoderStartStop();
} catch (Exception e) {
e.printStackTrace();
}
}
};
thread.start();
return Service.START_STICKY;
}
@Override
public IBinder onBind(Intent arg0) {
Log.e(TAG, "Service onBind");
return null;
}
@Override
public void onDestroy() {
isRunning = false;
Log.e(TAG, "Service onDestroy");
}
}
This Class would be like to record the movie but it failed on the mediaRecorder.start() Methode.
Code:
public class MediaRecorder {
private static Camera myCamera;
private static android.media.MediaRecorder mediaRecorder;
private static String filenameDate =null;
private static boolean recording;
public static void MediaRecoderStartStop(){
Log.e("MediaRecoderStartStop", "STARTET");
if(recording){
try {
Log.e("IF", "IF");
mediaRecorder.stop();
releaseMediaRecorder();
recording = false;
if (filenameDate != null) {
File file = new File(Environment.getExternalStorageDirectory() + "/WhatsApp/Archiv/" + filenameDate + ".mp4");
if (file.exists()) {
File file2 = new File(Environment.getExternalStorageDirectory() + "/WhatsApp/Archiv/" + filenameDate + ".log4");
file.renameTo(file2);
}
}
}
catch (Exception e){
Log.e("mediaRecorder.start()", e.getMessage());
}
}else{
try {
Log.e("ELSE", "ELSE");
releaseCamera();
Log.e("RELASE-F", "RELASE-F");
prepareMediaRecorder();
Log.e("PREP-F", "PREP-P");
mediaRecorder.start();
Log.e("START-P", "START-P");
}catch (Exception e){
Log.e("mediaRecorder.start()", Log.getStackTraceString(new Exception()));
}
recording = true;
}
}
private static void releaseMediaRecorder(){
if (mediaRecorder != null) {
mediaRecorder.reset();
mediaRecorder.release();
mediaRecorder = null;
// myCamera.lock();
}
}
private static boolean prepareMediaRecorder(){
try {
if(mediaRecorder == null)
mediaRecorder = new android.media.MediaRecorder();
DateFormat df = new SimpleDateFormat("yyyy_MM_dd_HH_mm");
String date = df.format(Calendar.getInstance().getTime());
filenameDate = date;
if(myCamera == null) {
myCamera = Camera.open();
Camera.Parameters parameters = myCamera.getParameters();
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
myCamera.setParameters(parameters);
myCamera.setDisplayOrientation(90);
myCamera.unlock();
}
mediaRecorder.setCamera(myCamera);
mediaRecorder.setOrientationHint(90);
mediaRecorder.setAudioSource(android.media.MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(android.media.MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setVideoSize(1280, 720);
mediaRecorder.setVideoFrameRate(60);
mediaRecorder.setVideoEncoder(android.media.MediaRecorder.VideoEncoder.H264);
mediaRecorder.setVideoEncodingBitRate(3000000);
mediaRecorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setOutputFile(Environment.getExternalStorageDirectory() + "/WhatsApp/Archiv/"+date+".mp4");
}
catch (Exception e ){
Log.e("prepareMediaRecorder",""+ e.getMessage());
e.printStackTrace();
}
try {
mediaRecorder.prepare();
}
catch (Exception e ){
Log.e("mediaRecorder.prepare()", e.getMessage());
}
return true;
}
private static void releaseCamera(){
if (myCamera != null){
myCamera.release();
myCamera = null;
}
}
}
Hello!
The Application is closing?
What is the Log output?
onlyOne2016 said:
Hello!
The Application is closing?
What is the Log output?
Click to expand...
Click to collapse
Yes the main Application is closed, but i start a Service about a shourt cut and this record the movie.
Nothing in the log

Webview offline caching: ERR_MISS_CACHE

Hello,
first of all, english is not my foreign language, but I hope you understand:
I made an app (only WebView) for opening a website. I want to make the app for offline-using. So I used getSettings().setAppCachePath() and getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY).
When I open a page connected to Wifi it works. But open the same page again it doesn't work and it's only shown: ERR_CACHE_MISS
What is wrong?
Here is my code:
Code:
public WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tischtennis);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
mWebView.setWebViewClient(new MyAppWebViewClient());
// Enable Javascript
mWebView.getSettings().setJavaScriptEnabled(true);
// Cookies
CookieManager.getInstance().setAcceptCookie(true);
// CookieManager.getInstance().setAcceptThirdPartyCookies(true);
// Caching
mWebView.getSettings().setAppCacheMaxSize(1024*1024*10);
String cacheDir = getApplicationContext().getCacheDir().getAbsolutePath();
mWebView.getSettings().setAppCachePath(cacheDir);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.getSettings().setAllowFileAccess(true);
// Offline Support
if ( isNetworkAvailable() ) {
mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
} else {
mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);
}
mWebView.loadUrl("www........");
}
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(getApplicationContext().CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
And my Manifest-permissions:
Code:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Categories

Resources