導航:首頁 > 操作系統 > androidhelloworld代碼

androidhelloworld代碼

發布時間:2022-09-08 19:46:59

Ⅰ 請問一下android開始默認創建的hello world代碼在哪,為什麼找不到。QAQ

res 里的layout文件夾裡面, activity_main

Ⅱ android 的HELLOWORLD

親,你能不能去官網看資料根據它的步驟一步一步來,寫好activity後需要在AndroidManifest.xml文件聲明的啊:
//AndroidManifest.xml

<activity android:name="ShortcutActivity"
android:theme="@style/ShortcutTheme"
android:label="@string/shortcut_bookmark"
android:icon="@mipmap/ic_launcher_shortcut_browser_bookmark">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>

</activity>

如果是主acitivy一般需要加入<action android:name="android.intent.action.MAIN" />
和<category android:name="android.intent.category.LAUNCHER" />

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

網址:http://developer.android.com/guide/components/index.html
打字不易,如滿意,望採納。

Ⅲ Android Studio怎麼用JNI編寫出Hello World

第一步:

在自己項目中創建一個包含native的方法類HelloWorld.java -->包名com.ningso.ningsodemo

public class HelloWorld {
public native String sayHello(String name); // 1.聲明這是一個native函數,由本地代碼實現
static {
System.loadLibrary("hello"); // 2.載入實現了native函數的動態庫,只需要寫動態庫的名字
}
}

第二步:

在終端執行javac命令將.java源文件編譯成.class位元組碼文件

完結


Ⅳ app android.mk 怎麼寫

一個Android.mk file用來向編譯系統描述你的源代碼。具體來說:該文件是GNU Makefile的一小部分,會被編譯系統解析一次或多次。你可以在每一個Android.mk file中定義一個或多個模塊,你也可以在幾個模塊中使用同一個源代碼文件。編譯系統為你處理許多細節問題。例如,你不需要在你的Android.mk中列出頭文件和依賴文件。NDK編譯系統將會為你自動處理這些問題。這也意味著,在升級NDK後,你應該得到新的toolchain/platform支持,而且不需要改變你的Android.mk文件。
先看一個簡單的例子:一個簡單的"hello world",比如下面的文件:
sources/helloworld/helloworld.c
sources/helloworld/Android.mk
相應的Android.mk文件會象下面這樣:
---------- cut here ------------------
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE
:= helloworld
LOCAL_SRC_FILES := helloworld.c
include $(BUILD_SHARED_LIBRARY)
---------- cut here ------------------
我們來解釋一下這幾行代碼:
LOCAL_PATH := $(call my-dir)
一個Android.mk file首先必須定義好LOCAL_PATH變數。它用於在開發樹中查找源文件。在這個例子中,宏函數』my-dir』, 由編譯系統提供,用於返回當前路徑(即包含Android.mk file文件的目錄)。
include $( CLEAR_VARS)
CLEAR_VARS由編譯系統提供,指定讓GNU MAKEFILE為你清除許多LOCAL_XXX變數(例如 LOCAL_MODULE, LOCAL_SRC_FILES, LOCAL_STATIC_LIBRARIES, 等等...),除LOCAL_PATH 。這是必要的,因為所有的編譯控制文件都在同一個GNU MAKE執行環境中,所有的變數都是全局的。
LOCAL_MODULE := helloworld
LOCAL_MODULE變數必須定義,以標識你在Android.mk文件中描述的每個模塊。名稱必須是唯一的,而且不包含任何空格。注意編譯系統會自動產生合適的前綴和後綴,換句話說,一個被命名為'foo'的共享庫模塊,將會生成'libfoo.so'文件。
LOCAL_SRC_FILES := helloworld.c
LOCAL_SRC_FILES變數必須包含將要編譯打包進模塊中的C或C++源代碼文件。注意,你不用在這里列出頭文件和包含文件,因為編譯系統將會自動為你找出依賴型的文件;僅僅列出直接傳遞給編譯器的源代碼文件就好。

在Android中增加本地程序或者庫,這些程序和庫與其所載路徑沒有任何關系,只和它們的Android.mk文件有關系。Android.mk和普通的Makefile有所不同,它具有統一的寫法,主要包含一些系統公共的宏。
在一個Android.mk中可以生成多個可執行程序、動態庫和靜態庫。
1,編譯應用程序的模板:
#Test Exe
LOCAL_PATH := $(call my-dir)
#include $(CLEAR_VARS)
LOCAL_SRC_FILES:= main.c
LOCAL_MODULE:= test_exe
#LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_EXECUTABLE)
(菜鳥級別解釋::=是賦值的意思,$是引用某變數的值)LOCAL_SRC_FILES中加入源文件路徑,LOCAL_C_INCLUDES 中加入所需要包含的頭文件路徑,LOCAL_STATIC_LIBRARIES加入所需要鏈接的靜態庫(*.a)的名稱,LOCAL_SHARED_LIBRARIES中加入所需要鏈接的動態庫(*.so)的名稱,LOCAL_MODULE表示模塊最終的名稱,BUILD_EXECUTABLE表示以一個可執行程序的方式進行編譯。
2,編譯靜態庫的模板:
#Test Static Lib
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= /
helloworld.c
LOCAL_MODULE:= libtest_static
#LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_STATIC_LIBRARY)
一般的和上面相似,BUILD_STATIC_LIBRARY表示編譯一個靜態庫。
3,編譯動態庫的模板:
#Test Shared Lib
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= /
helloworld.c
LOCAL_MODULE:= libtest_shared
TARGET_PRELINK_MODULES := false
#LOCAL_C_INCLUDES :=
#LOCAL_STATIC_LIBRARIES :=
#LOCAL_SHARED_LIBRARIES :=
include $(BUILD_SHARED_LIBRARY)
一般的和上面相似,BUILD_SHARED_LIBRARY表示編譯一個靜態庫。
以上三者的生成結果分別在如下,generic依具體target會變:
out/target/proct/generic/obj/EXECUTABLE
out/target/proct/generic/obj/STATIC_LIBRARY
out/target/proct/generic/obj/SHARED_LIBRARY
每個模塊的目標文件夾分別為:
可執行程序:XXX_intermediates
靜態庫: XXX_static_intermediates
動態庫: XXX_shared_intermediates
另外,在Android.mk文件中,還可以指定最後的目標安裝路徑,用LOCAL_MODULE_PATH和LOCAL_UNSTRIPPED_PATH來指定。不同的文件系統路徑用以下的宏進行選擇:
TARGET_ROOT_OUT:表示根文件系統。
TARGET_OUT:表示system文件系統。
TARGET_OUT_DATA:表示data文件系統。
用法如:
CAL_MODULE_PATH:=$(TARGET_ROOT_OUT)

Ⅳ 用eclipse寫一個簡單的android程序,要求在模擬器上點一下顯示一次helloworld,再點一下就消失了,求代碼

在你的layout里創建一個TextView,設好id和字元串:

<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text"
android:text="helloworld"
/>
</LinearLayout>


然後代碼這樣寫:

importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.MotionEvent;
importandroid.view.View;
importandroid.widget.TextView;
{
privateTextViewmTextView;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
//TODOAuto-generatedmethodstub
super.onCreate(savedInstanceState);
setContentView(R.id.main);
mTextView=(TextView)findViewById(R.id.text);
}
@Override
publicbooleanonTouchEvent(MotionEventevent){
//TODOAuto-generatedmethodstub
if(mTextView.getVisibility()==View.VISIBLE){
mTextView.setVisibility(View.INVISIBLE);
}
elseif(mTextView.getVisibility()==View.INVISIBLE){
mTextView.setVisibility(View.VISIBLE);
}
returnsuper.onTouchEvent(event);
}
}

Ⅵ 怎麼使用Android源碼編譯c模塊生成可執行文件

1. 在./development目錄下創建一目錄 如:myhello
2. 進入hello目錄,在其下編寫自己的.c文件,如: myhello.c
#include <stdio.h>
int main()
{
printf("hello world\n");
exit(0);
//return 0;
}
3. 在hello目錄中,編寫Android.mk, 內容如下:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := myhelloworld
LOCAL_SRC_FILES := myhello.c
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
4. 回到Android源代碼頂層目錄,進行編譯,make myhelloworld
5. 生成的可執行文件位於:out/target/proct/lotus/system/bin/ 目錄下
6. adb push 到手機 /data 目錄下,然後進入adb shell,到data目錄下,執行./myhelloworld 皆可

手動編譯連接【arm-eabi-gcc 的目錄隨andorid的版本而有變化,還有就是需要鏈接的文件如果比較多時,需要很多-l 就很麻煩了】
7、編譯成目標文件:
#$(yourAndroid)/prebuilt/linux-x86/toolchain/[arm-eabi-4.2.1]/bin/arm-eabi-gcc -I bionic/libc/arch-arm/include/ -I bionic/libc/include -I bionic/libc/kernel/common -I bionic/libc/kernel/arch-arm -g -c helloworld.c -o hello.o
8、生成可執行代碼:
#$(yourAndroid)/prebuilt/linux-x86/toolchain/[arm-eabi-4.2.1]/bin/arm-eabi-gcc -nostdlib -Bdynamic -Wl,-T,build/core/armelf.x -Wl,-dynamic-linker,/system/bin/linker -Wl,--gc-sections -Wl,-z,noreloc -o helloworld -Lout/target/proct/[generic]/obj/lib -Wl,-rpath-link=out/target/proct/[generic]/obj/lib -lc hello.o -entry=main

其中[ ]中部分根據實際情況修改

**************************************************
實驗:
1. 建目錄(my Android)/development/test, 在該目錄下新建 Android.mk和fb_test.c文件

2. Android.mk文件

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := myfbtest
LOCAL_SRC_FILES := fb_test.c
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)

3. 以下為fb_test.c
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include <linux/kd.h>

#include <stdio.h>

#define FBBIT_PER_PIXEL 32
#define FBBIT_PIXEL_IMAGE 16
#define PIXELS_WIDTH_BYTE 4
#define BYTE_PER_PIXEL 3
#define FB_GRAPHICS_PATH "/dev/graphics/fb0"
#define DEV_TTY0_PATH "/dev/tty0"

#define DISPLAY_ERROR -1
#define DISPLAY_SUCCESS 0

#define GET_BATTERYCAPACITY_ERR -1

#define MAX_STR 255

static struct {
int fd;
void *pixels;
struct fb_fix_screeninfo fixed;
struct fb_var_screeninfo var;
int align_xres;
} fb;

int getBatteryCapacity(void)
{
FILE *in;
char tmpStr[MAX_STR + 1];
char capfile[] = "/sys/class/power_supply/battery/capacity";

if (capfile == NULL)
return GET_BATTERYCAPACITY_ERR;

in = fopen(capfile, "rt");
if (in == NULL)
return GET_BATTERYCAPACITY_ERR;

if (fgets(tmpStr, MAX_STR, in) == NULL) {
printf("Failed to read battery capacity!\n");
fclose(in);
return GET_BATTERYCAPACITY_ERR;

}

printf("Battery capacity(ascii): %s\n", tmpStr);
fclose(in);

return 0;//atoi(tmpStr);
}

static int vt_set_graphicsmode(int graphics)
{
int fd, r;
fd = open(DEV_TTY0_PATH, O_RDWR | O_SYNC);
if (fd < 0)
return DISPLAY_ERROR;
r = ioctl(fd, KDSETMODE, graphics);
close(fd);
return r;
}

int display_init(void)
{
fb.fd = open(FB_GRAPHICS_PATH, O_RDWR);
if (fb.fd < 0)
return DISPLAY_ERROR;

if (ioctl(fb.fd, FBIOGET_FSCREENINFO, &fb.fixed) < 0)
return DISPLAY_ERROR;
if (ioctl(fb.fd, FBIOGET_VSCREENINFO, &fb.var) < 0)
return DISPLAY_ERROR;
fb.align_xres = fb.fixed.line_length /
(fb.var.bits_per_pixel >> BYTE_PER_PIXEL);

fb.pixels = mmap(0, fb.fixed.line_length * fb.var.yres_virtual,
PROT_READ | PROT_WRITE, MAP_SHARED, fb.fd, 0);
if (fb.pixels == MAP_FAILED)
return DISPLAY_ERROR;

vt_set_graphicsmode(KD_GRAPHICS);

memset(fb.pixels, 0, fb.fixed.line_length * fb.var.yres_virtual);
//display_update(fb.pixels, fb.align_xres, fb.var.yres);
fb.var.activate = FB_ACTIVATE_FORCE;
ioctl(fb.fd, FBIOPUT_VSCREENINFO, &fb.var);

printf("display_init ok\n");

return DISPLAY_SUCCESS;
}

void display_on(void)
{
ioctl(fb.fd, FBIOBLANK, FB_BLANK_UNBLANK);
}

void display_off(void)
{
ioctl(fb.fd, FBIOBLANK, FB_BLANK_POWERDOWN);
}

int main()
{
display_init();
display_off();//關顯示屏

getBatteryCapacity();
sleep(5);

display_on();//開顯示屏

return 0;
}

Ⅶ 急需一個簡單的Android程序,需源代碼!

//最簡單的helloword
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.widget.TextView;

{
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
TextViewtv=newTextView(this);
tv.setText("Hello,World!");
setContentView(tv);
}
}

Ⅷ android簡單helloword問題

很簡單 新建了TextView 然後設置文本顯示「Hello World"

android里的Manifest.xml文件里這樣設置
<?xml version ="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
/>
</LinearLayout>
主程序這樣就OK
package com.example.helloworld;
import android.os.Bundle;
import android.app.Activity;

public class HelloWorld extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

}
}

Ⅸ android androidhelloworld怎麼寫

apk 只是個壓縮包,安裝是個解壓,java 代碼在安卓里,與平常所編的代碼是一樣的。

閱讀全文

與androidhelloworld代碼相關的資料

熱點內容
安卓怎麼弄成蘋果在線 瀏覽:431
谷歌web伺服器地址 瀏覽:898
安卓鎖屏圖片如何刪除 瀏覽:719
python3多進程編程 瀏覽:713
證明代碼是程序員寫的 瀏覽:396
演算法錯誤發現辦法 瀏覽:409
河南省醫院掛號是哪個app 瀏覽:629
冬日戀歌哪個APP能看 瀏覽:673
委內瑞拉加密貨 瀏覽:10
程序員寫日記哪個軟體好 瀏覽:108
加密機操作手冊 瀏覽:860
dos命令自動關閉 瀏覽:328
心田花開app在哪裡評價 瀏覽:449
求索記錄頻道哪個app可以看 瀏覽:730
金梅瓶pdf下載 瀏覽:985
機器軟體用什麼編程 瀏覽:845
java虛擬機指令 瀏覽:671
shell編程入門書籍 瀏覽:946
大連桶裝水溯源碼售價 瀏覽:302
php怎麼跳轉到電腦 瀏覽:415