Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Get package name Context-getPackageName Android example

If you often copy your Android project to another you have to using function for obtaining varied information about package.
This code show how get package name in Android application as string:

Context context = getContext(); // this.getContext(); getApplicationContext(); etc.
String sPackName = context.getPackageName();


396LW NO topic_id




AD

Další témata ....(Topics)


139

drawBitmap createBitmap by array of colours Android example | drawbitmap-createbitmap-draw-bitmap-by-array-of-colours-android-example


public static Bitmap createBitmap (int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)
public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)

//  //www.apache.org/licenses/LICENSE-2.0
public class MainActivity extends Activity {
	    private static final int WIDTH = 50;
	    private static final int HEIGHT = 50;
	    private static final int STRIDE = 64;   // must be >= WIDTH
	    
	    private static int[] createColors() {
	        int[] colors = new int[STRIDE * HEIGHT];
	        for (int y = 0; y < HEIGHT; y++) {
	            for (int x = 0; x < WIDTH; x++) {
	                int r = x * 255 / (WIDTH - 1);
	                int g = y * 255 / (HEIGHT - 1);
	                int b = 255 - Math.min(r, g);
	                int a = Math.max(r, g);
	                colors[y * STRIDE + x] = (a << 24) | (r << 16) | (g << 8) | b;
	            }
	        }
	        return colors;
	    }
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}
		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();
			
			canvas.drawColor(Color.GREEN);

            int[] mColors = createColors();
            int[] colors = mColors;

           
            Bitmap bitmap = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
                    Bitmap.Config.RGB_565);
                      
			canvas.drawBitmap(bitmap, 50,20, paint); 
		}

	}
}


70

Foreach loop cycle in Java Android example | foreach-loop-cycle-in-java-android-example


Foreach in Java basic example source code.

MainClass.java


public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = { "Hello", "people", "hello", "world!" };

		for (String s : arrayOfString)
			System.out.println(s);

	}
}

234

Programmatically determine if App is running on Android Emulator | programmatically-determine-if-app-is-running-on-android-emulator


You can get list by class Build
For example:

if(Build.MANUFACTURER.equals("unknown")) {
		// Emulator
	}


List of Build class getting from emulator:
"BOARD=unknown
BRAND=generic
CPU_ABI=armeabi
DEVICE=generic
DISPLAY=sdk-eng 2.1-update1 ECLAIR 35983 test-keys
FINGERPRINT=generic/sdk/generic/:2.1-update1/ECLAIR/35983:eng/test-keys
HOST=android-test-13.mtv.corp.google.com
ID=ECLAIR
MANUFACTURER=unknown
MODEL=sdk
PRODUCT=sdk
TAGS=test-keys
TIME=1273161972000
TYPE=eng
USER=android-build
"
338

ActivityThread: Failed to find provider Sqlite database | activitythread-failed-to-find-provider-sqlite-database


Issue:
ActivityThread: Failed to find provider

Try check this authority tags if they are all the same:
(com.yourdomen.yourproject.YourContentProviderClass replace your path to YourContentProviderClass)

res/xml/serchable.xml
Tag searchable

<searchable xmlns:android="//schemas.android.com/apk/res/android"
android:blahblah 
......
android:searchSuggestAuthority="com.yourdomen.yourproject.YourContentProviderClass"


AndroidManifest.xml
Tag provider

 <provider android:name=".YourContentProviderClass"
                  android:authorities="com.yourdomen.yourproject.YourContentProviderClass" />

179

HTC Incredible 2 | htc-incredible-2


HTC Incredible 2 cena od 6 000 KCZ Kč (únor.2012)
Spokojenost uživatelů nadprůměrná.
HTC Incredible 2 je chytrý telefon s operačním systémem Android.
HTC Incredible 2 je (22.února2012) 7. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.

HTC Incredible 2 - video recense