2013年10月31日 星期四

Native Wallpaper picker

That is my question. For them who dont know what i am asking, I want to make this menu to appear in my app http://db.tt/GQX9GBYF . The thing is that I Dont have any idea how to do it. I think that I have to create an intent, from it obtain image path and then, set it as background. But i dont know the exact way to do it...
Please, anyone could post me an example, please???? ;)
I have to say that I managed to do it by launching native gallery app, but I want to set live wallpapers too
share|improve this question
You Intent.ACTION_SET_WALLPAPER for starting ContaxtMenu for Selecting Wallpaper as:
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));
share|improve this answer
 
ok it worked, but it sets launcher background, and I only want to set wallpaper for my app... any idea?? THANKS A LOT!! –  BamsBamx May 27 '12 at 16:13
 
myLayout.setBackgroundDrawable(getWallpaper()); gets the wallpaper and sets it for your layout – user1446632 Feb 10 at 19:07

2013年10月30日 星期三

pick photo with crop & set wallpaper :)

package com.example.testallstar;

import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import android.media.AudioManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MainActivity extends Activity {
private static final int SELECT_PHOTO = 100;

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

Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
photoPickerIntent.putExtra("crop", "true");

startActivityForResult(photoPickerIntent, SELECT_PHOTO);


}

@Override
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
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
   super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

   switch(requestCode) {
   case SELECT_PHOTO:
       if(resultCode == RESULT_OK){
           Uri selectedImage = imageReturnedIntent.getData();
           InputStream imageStream = null;
try {
imageStream = getContentResolver().openInputStream(selectedImage);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
           Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
           WallpaperManager wpm = WallpaperManager.getInstance(getBaseContext());
           try {
wpm.setBitmap(yourSelectedImage);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
       }
   }
}




}

2013年10月28日 星期一

call自動轉speaker

package com.example.testallstar;

import java.io.DataOutputStream;
import java.io.IOException;

import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends Activity {

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

TelephonyManager manager = (TelephonyManager) this
.getSystemService(TELEPHONY_SERVICE);

manager.listen(new MyPhoneStateListener(),
PhoneStateListener.LISTEN_CALL_STATE);

}

@Override
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;
}

class MyPhoneStateListener extends PhoneStateListener {

@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
Toast.makeText(getApplicationContext(), "Phone Free",
Toast.LENGTH_SHORT).show();
break;
case TelephonyManager.CALL_STATE_RINGING:
Toast.makeText(getApplicationContext(),
"  手台鈴聲響了,來電號碼:" + incomingNumber, Toast.LENGTH_SHORT)
.show();

break;
case TelephonyManager.CALL_STATE_OFFHOOK:
Toast.makeText(getApplicationContext(), "電話完成掛起",
Toast.LENGTH_SHORT).show();
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);
default:
break;
}

super.onCallStateChanged(state, incomingNumber);
}

}

}

----------------------------------------------------------------------
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

turn on airplane mode (root shell command)

package com.example.testallstar;

import java.io.DataOutputStream;
import java.io.IOException;

import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.app.Activity;
import android.content.Intent;
import android.telephony.ServiceState;
import android.view.Menu;

public class MainActivity extends Activity {

String[] commands = {"sysrw", "settings put global airplane_mode_on 1\nam broadcast -a android.intent.action.AIRPLANE_MODE --ez state true", "sysro"};

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

@Override
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;
}

public void RunAsRoot(String[] cmds) {
Process p = null;
try {
p = Runtime.getRuntime().exec("su");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DataOutputStream os = new DataOutputStream(p.getOutputStream());
for (String tmpCmd : cmds) {
try {
os.writeBytes(tmpCmd + "\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
os.writeBytes("exit\n");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
os.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

//------------------------------------------------------------------------------------

4down voteaccepted
There is a new "settings" binary in Android 4.2 You can also use it without su, then your app needs the permission required to change this setting declared in your app's manifest (which would be WRITE_SECURE_SETTINGS for flight mode in 4.2 - which is only granted to apps installed on system partition).
Activate
su 
settings put global airplane_mode_on 1
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true
Deactivate
su
settings put global airplane_mode_on 0
am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false
For other android versions and other settings (flight mode can be activated without root before 4.2) you can use sql injects in settings.db
su
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
insert into global values(null, 'airplane_mode_on', 1);
Replace "global" with "system" or "secure" and 'airplane_mode_on' with the key of your desired table entry. For some settings you need to send certain broadcasts afterwards, see example above for flight mode.
To explore your settings.db run this in a terminal app:
su
sqlite3 /data/data/com.android.providers.settings/databases/settings.db
.tables
select * from global
select * from secure
select * from system
share|improve this answer

Disable lockscreen

I am looking for a way to replace the stock lock screen (with an app, not a rom). What is the best way to do it, for a start to disable the lock screen on as much devices as possible? Thanks!
share|improve this question

4 Answers

KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
lock.disableKeyguard();
in androidmanifest:
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
share|improve this answer
3 
perfect. Thank you very much –  Weldeborn Jul 6 '11 at 6:38
2 
The class KeyguardLock has been deprecated. Setting the window flags as shown by @hsgubert below seems the current way to turn off the key guard/lock screen. –  pstoppani Feb 1 at 0:48
Related Posts Plugin for WordPress, Blogger...