简体   繁体   中英

Android application launch from a widget

Below is a code to launch an application from a widget... It's not working, any suggestions? Thank You

package com.acd.widget;
import android.appwidget.AppWidgetProvider;
import android.content.Intent;

public class AcdWidget extends AppWidgetProvider {
   String packageName = "air.kwd.acdsummit";
   String className = "com.package.MainActivity";
   Intent intent = new Intent(Intent.ACTION_MAIN);
   intent.setComponent(new ComponentName(packageName, className));
   startActivity(intent);
}

You need to invoke the statements in some event listener (like OnClick). You are invoking them outside a method, where declarations (of fields, methods) are expected.

Read the App Widgets developer guide for more information on how you can achieve what you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM