getmethodid( android/widget/toast ),android - how to present a toast when a widget is clicked? - St...

Try this:

button = (Button) findViewById(R.id.buttonToast);

button.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// Create a piece of toast.

Toast pieceToast = Toast.makeText(getApplicationContext(), "Test Message", Toast.LENGTH_SHORT);

// Show the toast.

pieceToast.show();

}

This is my BroadcastReciever Class:

public class IncomingCallReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

Bundle bundle = intent.getExtras();

if(null == bundle)

return;

Log.i("IncomingCallReceiver",bundle.toString());

String state = bundle.getString(TelephonyManager.EXTRA_STATE);

String registredPhoneNumber;

Log.i("IncomingCallReceiver","State: "+ state);

String phonenumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

System.out.println("*****Mobile Ringing*******"+phonenumber);

if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))

{

registredPhoneNumber = PreferenceConnector.getPhoneNumber(context);

System.out.println("registredPhoneNumber: "+registredPhoneNumber);

System.out.println("phonenumber: "+phonenumber);

Log.i("IncomingCallReceiver","Incomng Number: " + phonenumber);

if(phonenumber.equals(registredPhoneNumber)){

System.out.println("Entered...");

String info = "Detect Calls sample application\nIncoming number: " + phonenumber;

if(isMyServiceRunning(context)){

context.stopService(new Intent(context,com.visiomaticamericas.visitormobile.services.LaunchServiceActivity.class));

System.out.println("******Service Stopped*********");

}

Intent i = new Intent(context,com.services.LaunchServiceActivity.class);

i.putExtra("delay",500L);

context.startService(i);

System.out.println("*****Service Started*****");

Toast.makeText(context, info, Toast.LENGTH_LONG).show();

}

}

}

}

Here, I called my activity class.. and I did my widget design in My activity class..

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 10中,应用程序需要请求MANAGE_EXTERNAL_STORAGE权限才能创建公共存储目录。同时,由于安全原因,应用程序无法直接访问/sdcard/目录,因此需要使用getExternalFilesDir()方法获取应用程序私有目录的路径。 以下是使用C语言在Android 10中创建/sdcard/Android/data/com.xxxxx目录的步骤: 1. 在AndroidManifest.xml文件中添加以下权限: ``` <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/> ``` 2. 在应用程序中请求MANAGE_EXTERNAL_STORAGE权限: ``` ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.MANAGE_EXTERNAL_STORAGE}, 1); ``` 3. 获取应用程序私有目录的路径: ``` char* privateDirPath = NULL; JNIEnv* env = NULL; JavaVM* vm = NULL; jint result = (*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_6); if (result != JNI_OK) { result = (*vm)->AttachCurrentThread(vm, &env, NULL); if (result != JNI_OK) { return NULL; } } jobject context = getCurrentContext(env); jclass contextClass = (*env)->GetObjectClass(env, context); jmethodID getExternalFilesDirMethod = (*env)->GetMethodID(env, contextClass, "getExternalFilesDir", "(Ljava/lang/String;)Ljava/io/File;"); jstring type = (*env)->NewStringUTF(env, NULL); jobject file = (*env)->CallObjectMethod(env, context, getExternalFilesDirMethod, type); const char* fileStr = (*env)->GetStringUTFChars(env, file, 0); privateDirPath = strdup(fileStr); (*env)->ReleaseStringUTFChars(env, file, fileStr); (*vm)->DetachCurrentThread(vm); ``` 4. 使用mkdir()函数创建目录: ``` char* dirPath = "/sdcard/Android/data/com.xxxxx"; strcat(privateDirPath, dirPath); int result = mkdir(privateDirPath, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); if (result == -1) { // 创建目录失败 } ``` 注意:如果应用程序没有MANAGE_EXTERNAL_STORAGE权限,则会在运行时抛出SecurityException异常。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值